Skip to content

Commit

Permalink
Begin to translate patch from kurahaupo++ into configuration step pro…
Browse files Browse the repository at this point in the history
…be. Not actually set up yet.

git-svn-id: https://svn.parrot.org/parrot/branches/tt1824_ipv6_configure@49532 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
jkeenan committed Oct 14, 2010
1 parent 454fac1 commit 83ece16
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 84 deletions.
28 changes: 8 additions & 20 deletions config/auto/ipv6.pm
Expand Up @@ -3,15 +3,16 @@

=head1 NAME
config/auto/va_ptr.pm - va_list to va_ptr conversion test
config/auto/ipv6.pm - determine ipv6 capabilities of local machine
=head1 DESCRIPTION
Tests which kind of PARROT_VA_TO_VAPTR to use.
This configuration step probes the local machine to determine if it capable of
running an ipv6 stack.
=cut

package auto::va_ptr;
package auto::ipv6;

use strict;
use warnings;
Expand All @@ -24,31 +25,18 @@ use Parrot::Configure::Utils ':auto';
sub _init {
my $self = shift;
my %data;
$data{description} = q{Test the type of va_ptr};
$data{description} = q{Determine IPV6 capabilities};
$data{result} = q{};
return \%data;
}

sub runstep {
my ( $self, $conf ) = @_;

my $va_type;
$conf->cc_gen('config/auto/va_ptr/test_c.in');
eval { $conf->cc_build('-DVA_TYPE_STACK'); };

if ( $@ || $conf->cc_run() !~ /^ok/ ) {
eval { $conf->cc_build('-DVA_TYPE_REGISTER'); };
if ( $@ || $conf->cc_run() !~ /^ok/ ) {
die "Unknown va_ptr type";
}
$va_type = 'register';
}
else {
$va_type = 'stack';
}
$conf->cc_gen('config/auto/ipv6/test.in');
$conf->cc_clean();
$self->set_result($va_type);
$conf->data->set( va_ptr_type => $va_type );
$self->set_result();
$conf->data->set( ipv6 => undef );

return 1;
}
Expand Down
104 changes: 48 additions & 56 deletions config/auto/ipv6/test.in
Expand Up @@ -4,70 +4,62 @@ $Id$

*/

#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>

#if defined VA_TYPE_REGISTER
# define PARROT_VA_TO_VAPTR(x) (x)
#endif
#if defined VA_TYPE_STACK
# define PARROT_VA_TO_VAPTR(x) (&(x))
#endif
int main(int c,char**v) {
int x = socket( PF_INET6, SOCK_DGRAM, 0 );
if ( x < 0 ) {
perror("Not OK - socket failed");
return 2;
}

typedef struct a_t {
void *args;
} arg;
/*
By now we have (a) PF_INET6 defined, and (b) in-principle kernel
support for v6; however we don't yet know if we have any v6
interfaces.
*/

static void
test2(arg *a) {

va_list *ap = (va_list*)a->args;
int i;
double d;
char *s;
struct in6_addr A = IN6ADDR_LOOPBACK_INIT; /* IN6ADDR_ANY_INIT; */
struct sockaddr_in6 S = { AF_INET6 }; /* family is always first field in sockaddr_* */
S.sin6_addr = A;
S.sin6_port = 32760; /* a pseudorandom 15-bit number */
*/
/*
By now we have struct in6_addr, struct sockaddr_in6 and AF_INET6 and
IN6ADDR_LOOPBACK_INIT. But we still don't know about interfaces.
*/

i = va_arg(*ap, int);
d = va_arg(*ap, double);
s = va_arg(*ap, char *);
if (i == 42 && d == 2.0)
printf("%s\n", s);
else
printf("nok\n");
}
#ifdef linux /* might not be supported elsewhere */
S.sin6_flowinfo = 0;
S.sin6_scope_id = 0;
#endif

static void
test1(va_list ap)
{
arg a;
a.args = PARROT_VA_TO_VAPTR(ap);
test2(&a);
}
/*
Set the SO_REUSEADDR option so as not to interfere with anyone else
using the port, including running this test again within the
re-use timeout period.
*/
int reuse_address = 1;
if ( setsockopt(x, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0 ) {
perror("Not OK - setsockopt failed");
return 1;
}

/*
* Visual C++ dies with an Internal Compiler Error when compiling the
* following function using -O2. Don't know why, but maybe because of this:
* https://connect.microsoft.com/VisualStudio/feedback/details/457892/internal-compiler-error
* Disable optimizations for this function using a pragma.
*/
#if defined _MSC_VER
# pragma optimize("t", off)
#endif
static void
test0(int n, ...)
{
va_list ap;
va_start(ap, n);
test1(ap);
va_end(ap);
}
#if defined _MSC_VER
# pragma optimize("", on)
#endif
if ( bind( x, (void*) &S, sizeof(S) ) < 0 && errno != EADDRINUSE ) {
perror("Not OK - bind failed");
return 1;
}

int
main(int argc, char *argv[])
{
test0(3, 42, 2.0, "ok");
/*
By now we know we can bind to "::1", which means we truly do have
IPv6 support. Of course, we might not have any useful routes off
this host, but that wasn't the question.
*/
puts("OK");
close(x);
return 0;
}

Expand Down
16 changes: 8 additions & 8 deletions t/steps/auto/ipv6-01.t
@@ -1,14 +1,14 @@
#! perl
# Copyright (C) 2007, Parrot Foundation.
# $Id$
# auto/va_ptr-01.t
# auto/ipv6-01.t

use strict;
use warnings;
use Test::More tests => 5;
use Test::More qw(no_plan); # tests => 5;
use Carp;
use lib qw( lib t/configure/testlib );
use_ok('config::auto::va_ptr');
use_ok('config::auto::ipv6');
use Parrot::Configure::Options qw( process_options );
use Parrot::Configure::Step::Test;
use Parrot::Configure::Test qw(
Expand All @@ -25,7 +25,7 @@ my ($args, $step_list_ref) = process_options(
my $conf = Parrot::Configure::Step::Test->new;
$conf->include_config_results( $args );

my $pkg = q{auto::va_ptr};
my $pkg = q{auto::ipv6};
$conf->add_steps($pkg);
$conf->options->set( %{$args} );
my $step = test_step_constructor_and_description($conf);
Expand All @@ -36,25 +36,25 @@ pass("Completed all tests in $0");

=head1 NAME
auto/va_ptr-01.t - test auto::va_ptr
auto/ipv6-01.t - test auto::ipv6
=head1 SYNOPSIS
% prove t/steps/auto/va_ptr-01.t
% prove t/steps/auto/ipv6-01.t
=head1 DESCRIPTION
The files in this directory test functionality used by F<Configure.pl>.
The tests in this file test auto::va_ptr.
The tests in this file test auto::ipv6.
=head1 AUTHOR
James E Keenan
=head1 SEE ALSO
config::auto::va_ptr, F<Configure.pl>.
config::auto::ipv6, F<Configure.pl>.
=cut

Expand Down

0 comments on commit 83ece16

Please sign in to comment.