Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
skeleton implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
potatogim committed May 13, 2017
1 parent b14a696 commit 89c3248
Show file tree
Hide file tree
Showing 14 changed files with 714 additions and 5 deletions.
222 changes: 222 additions & 0 deletions .TRAVIS.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#/usr/bin/env perl

use strict;
use warnings;
use utf8;

use Cwd ();
use Symbol qw/gensym/;
use IPC::Open3 qw/open3/;
use IO::Select;
use POSIX qw/:sys_wait_h/;

use Test::Most;

sub run_cmd (@)
{
my %args = @_;

my $cmd = $args{cmd};
my @args = defined($args{args}) ? @{$args{args}} : ();
my $in = $args{in};
my $timeout = $args{timeout};
my $quiet = $args{quiet};
my $cb_out = $args{cb_out};
my $cb_err = $args{cb_err};
my $nb = $args{nb} // 4096;

if (!defined($cmd))
{
warn '[ERR] Invalid parameter: cmd';
return undef;
}

$timeout = 60 if (!defined($timeout) || $timeout !~ m/^\d+$/);
$timeout = undef if ($timeout == 0);

# :TODO 12/31/2014 03:47:37 PM Ji-Hyeon Gim
# 예전에 잠깐 집어넣었다가 안쓸거 같아서 뺐었던 기억이 나는데...
# 매개변수 in에 문자열이 아니라 파일 핸들을 받는 경우에 대한 처리를
# 포함할 것인지 생각해보자.
# 그럴 경우 예전처럼 gensym으로 만들어진 cmd_in이 아니라 바로 in을
# 넘겨주면 되는거니까...

# generate symbol
my ($cmd_in, $cmd_out, $cmd_err) = map gensym, 1..3;

# Open Process
my $pid = open3($cmd_in, $cmd_out, $cmd_err, $cmd, @args);
my $start = time;

# For selecting.
my $select_handle = IO::Select->new();

if (defined($in))
{
print $cmd_in $in;

#$select_handle->add($cmd_in);
#
#while (my @ready = $select_handle->can_write($timeout))
#{
# foreach my $handle (@ready)
# {
# syswrite($handle, $in);
# }
#}
#
#$select_handle->remove($cmd_in);
}

$select_handle->add($cmd_out);
$select_handle->add($cmd_err);

my $out = '';
my $err = '';

while (my @ready = $select_handle->can_read($timeout))
{
foreach my $handle (@ready)
{
my $buf = '';

# Non-Buffered I/O
if ($nb)
{
if (sysread($handle, $buf, $nb))
{
if ($handle == $cmd_out)
{
if ($cb_out)
{
local $_ = $buf;
chomp($_);
$cb_out->();
}

$out .= $buf;
}
elsif ($handle == $cmd_err)
{
if ($cb_err)
{
local $_ = $buf;
chomp($_);
$cb_err->();
}

$err .= $buf;
}
}
else
{
# EOF or Error
$select_handle->remove($handle);
}
}
else
{
$buf = <$handle>;

if ($buf)
{
if ($handle == $cmd_out)
{
if ($cb_out)
{
local $_ = $buf;
chomp($_);
$cb_out->();
}

$out .= $buf;
}
elsif ($handle == $cmd_err)
{
if ($cb_err)
{
local $_ = $buf;
chomp($_);
$cb_err->();
}

$err .= $buf;
}
}
else
{
# EOF or Error
$select_handle->remove($handle);
}
}
}
}

close($cmd_in);
close($cmd_out);
close($cmd_err);

my $is_timeout = 0;

# check whether timeout or not.
if ($select_handle->count)
{
kill('TERM', $pid);
$is_timeout = 1;
}

my ($kid, $reap_count) = (0, 0);

do {
select(undef, undef, undef, 0.05);
$kid = waitpid($pid, WNOHANG);
} until ($kid > 0 || ++$reap_count >= 10);

my $status = undef;

if ($kid > 0)
{
$status = $?>>8;
}

chomp($out);
chomp($err);

if ($out =~ m/^open3:/)
{
warn "[ERR] Failed to execute with open3: $cmd";
return undef;
}

return {
cmd => @args ? join(' ', $cmd, @args) : $cmd,
pid => $kid,
status => ($is_timeout) ? -1 : $status,
out => $out,
err => ($is_timeout) ? 'Timeout exceeded' : $err,
runtime => time - $start,
};
}

sub test_libgfapi
{
my $retval = run_cmd(
cmd => 'make test TEST_VERBOSE=1',
cb_out => sub { print STDOUT "$_\n"; },
cb_err => sub { print STDERR "$_\n"; });

if (!defined($retval) || $retval->{status})
{
die $retval->{status};
}

return 0;
}

our $ROOT = Cwd::abs_path(Cwd::cwd());

ok(1, 'libgfapi-perl');

test_libgfapi();

done_testing();
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.swp
*.old
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
branches:
only:
- master
- /^v\d/

notifications:
email: false

sudo: required

language: perl

dist: trusty

perl:
- "5.10"
- "5.14"
- "5.18"
- "5.20"
- "5.22"
- "5.24"

before_install:
- sudo apt-get update
- sudo apt-get install -y glusterfs-server glusterfs-client libacl1 attr

install:
- cpanm -quiet --notest --skip-satisfied --installdeps .

script:
- perl .TRAVIS.PL
34 changes: 34 additions & 0 deletions .travis.yml.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
branches:
only:
- master
- /^v\d/

notifications:
email: false

sudo: required

services:
- docker

env:
matrix:
- OS_TYPE=centos:6
- OS_TYPE=centos:7

language: perl

perl:
- "5.24"

before_install:
- sudo apt-get update
- echo 'DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -s devicemapper"' | sudo tee /etc/default/docker > /dev/null
- sudo service docker restart
- sleep 5
- sudo docker pull $OS_TYPE

install: "perl -e 1" # dummy

script:
- "perl t/travis.t ${OS_TYPE}"
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

0.01 2017-05-13 19:21:45 Asia/Seoul

- Initial release
12 changes: 9 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
This software is Copyright (c) 2017 by Ji-Hyeon Gim.

This is free software, licensed under:

The GNU General Public License, Version 3, June 2007

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Expand Down Expand Up @@ -631,8 +637,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -652,7 +658,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

{project} Copyright (C) {year} {fullname}
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
67 changes: 67 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use strict;
use warnings FATAL => 'all';
use ExtUtils::MakeMaker;

WriteMakefile(
NAME => 'GlusterFS::GFAPI::FFI',
DISTNAME => 'GlusterFS-GFAPI-FFI',
AUTHOR => 'Ji-Hyeon Gim <[email protected]>',
VERSION_FROM => 'lib/GlusterFS/GFAPI/FFI.pm',
ABSTRACT_FROM => 'lib/GlusterFS/GFAPI/FFI.pm',
LICENSE => 'perl',
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => 0,
'FFI::CheckLib' => 0,
'FFI::Platypus' => 0,
},
BUILD_REQUIRES => {
'ExtUtils::MakeMaker' => 0,
},
PREREQ_PM => {
'Carp' => 0,
'FFI::Platypus' => 0,
'FFI::Platypus::Buffer' => 0,
'FFI::Platypus::Memory' => 0,
'Try::Tiny' => 0,
'strict' => 0,
'warnings' => 0,
'threads' => 0,
},
TEST_REQUIRES => {
'Symbol' => 0,
'IPC::Open3' => 0,
'IO::Select' => 0,
'List::Util' => 0,
'POSIX' => 0,
'Scalar::Util' => 0,
'Test::Deep' => 0,
'Test::More' => 0,
'Time::HiRes' => 0,
'locale' => 0,
'utf8' => 0,
},
EXE_FILES => [],
dist => {
COMPRESS => 'gzip -9f',
SUFFIX => 'gz',
},
clean => {
FILES => 'GlusterFS-GFAPI-FFI-*',
},
test => {
'TESTS' => "t/*.t",
},
(
eval { ExtUtils::MakeMaker->VERSION(6.46) }
? (
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
type => 'git',
url => 'https://github.com/potatogim/libgfapi-perl.git',
web => 'https://github.com/potatogim/libgfapi-perl',
},
})
: ()
),
);
Loading

0 comments on commit 89c3248

Please sign in to comment.