This repository has been archived by the owner on Jan 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
714 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.swp | ||
*.old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}) | ||
: () | ||
), | ||
); |
Oops, something went wrong.