commit a450194264ab7405600a3c3469e2cea761437a4b
parent 2fcacced9674eaf324e698ac140c1d7464cac42c
Author: Kyle Milz <kyle@0x30.net>
Date: Thu, 18 Aug 2016 18:36:44 -0600
test: use new citrun-dump utility to start overhauling runtime tests
Diffstat:
7 files changed, 169 insertions(+), 158 deletions(-)
diff --git a/Jamrules b/Jamrules
@@ -41,6 +41,7 @@ if $(OS) = OPENBSD {
LINKLIBS on citrun-gl = -lestdc++ -lm -lglut ;
LINKLIBS on citrun-inst = -lestdc++ ;
LINKLIBS on citrun-term = -lestdc++ ;
+ LINKLIBS on citrun-dump = -L/usr/local/lib -lestdc++ ;
}
if $(OS) = MACOSX {
diff --git a/src/Jamfile b/src/Jamfile
@@ -16,6 +16,10 @@ Shell citrun-check : check.in ;
# utils.a
Library utils : shm.cc runtime_proc.cc ;
+# citrun-dump
+LinkLibraries citrun-dump : utils ;
+Main citrun-dump : dump_main.cc ;
+
#
# citrun-term
#
diff --git a/src/dump_main.cc b/src/dump_main.cc
@@ -0,0 +1,60 @@
+//
+// Tool used by the end to end tests.
+//
+#include "shm.h"
+#include "runtime_proc.h"
+
+#include <cstring>
+#include <iostream>
+#include <unistd.h> // getopt
+
+static void
+usage()
+{
+ std::cerr << "usage: citrun-dump [-f]" << std::endl;
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int ch;
+ int fflag = 0;
+
+ while ((ch = getopt(argc, argv, "f")) != -1) {
+ switch (ch) {
+ case 'f':
+ fflag = 1;
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ shm shm_conn;
+ RuntimeProcess rt(shm_conn);
+
+ if (fflag) {
+ for (auto &t : rt.m_tus) {
+ std::cout << t.comp_file_path << " "
+ << t.num_lines << std::endl;
+ }
+
+ return 0;
+ }
+
+ std::cout << "Version: "
+ << unsigned(rt.m_major) << "."
+ << unsigned(rt.m_minor) << "\n"
+ << "Program name: " << rt.m_progname << "\n"
+ << "Working directory: " << rt.m_cwd << "\n"
+ << "Translation units: " << rt.m_tus.size() << "\n"
+ << "Process ID: " << rt.m_pid << "\n"
+ << "Parent process ID: " << rt.m_ppid << "\n"
+ << "Process group ID: " << rt.m_pgrp << "\n";
+
+ return 0;
+}
diff --git a/t/rt_static.t b/t/rt_static.t
@@ -1,35 +1,31 @@
-use strict;
-use Cwd;
-use Test::More tests => 21;
-use test::project;
-use test::viewer;
+#!/bin/sh
+#
+# Test that the basic static structure of the shared memory region is what we
+# expect.
+#
+echo 1..4
+. test/project.sh
-my $project = test::project->new();
-my $viewer = test::viewer->new();
+./program 45 &
+pid=$!
-$project->run(45);
+$TEST_TOOLS/citrun-dump | grep -e "Versi" -e "Progr" -e "Translat" > dump.out
+$TEST_TOOLS/citrun-dump -f > filelist.out
-$viewer->accept();
-is( $viewer->{maj}, 0, "protocol major version" );
-is( $viewer->{min}, 0, "protocol minor version" );
-is( $viewer->{ntus}, 3, "translation unit count" );
-is( $viewer->{progname}, "program", "program name" );
-is( $viewer->{cwd}, getcwd, "current working dir" );
-is( @{ $viewer->{pids} }, 3, "number of pids" );
-cmp_ok( $viewer->{pids}->[0], ">", 1, "pid check lower" );
-cmp_ok( $viewer->{pids}->[0], "<", 100000, "pid check upper" );
-cmp_ok( $viewer->{pids}->[1], ">", 1, "ppid check lower" );
-cmp_ok( $viewer->{pids}->[1], "<", 100000, "ppid check upper" );
-cmp_ok( $viewer->{pids}->[2], ">", 1, "pgrp check lower" );
-cmp_ok( $viewer->{pids}->[2], "<", 100000, "pgrp check upper" );
+kill -USR1 $pid
+wait
+[ $? -eq 0 ] && echo ok 2 - program return code after SIGUSR1
-$viewer->cmp_static_data([
- [ "one.c", 34 ],
- [ "three.c", 9 ],
- [ "two.c", 11 ],
-]);
+cat <<EOF > dump.good
+Version: 0.0
+Program name: program
+Translation units: 3
+EOF
+test_diff 3 "citrun-dump output" dump.out dump.good
-$project->kill();
-my ($ret, $err) = $project->wait();
-is( $ret, 0, "instrumented program check return code" );
-is( $err, undef, "instrumented program check stderr" );
+cat <<EOF > filelist.good
+one.c 34
+three.c 9
+two.c 11
+EOF
+filelist_diff 4
diff --git a/test/project.pm b/test/project.pm
@@ -1,128 +0,0 @@
-package test::project;
-use strict;
-
-use Cwd;
-use File::Temp qw( tempdir );
-use Test;
-use IPC::Open2;
-
-sub new {
- my ($class) = @_;
- my $self = {};
- bless ($self, $class);
-
- # Make new temporary directory, clean it up at exit
- my $tmp_dir = tempdir( CLEANUP => 1 );
-
- # Use the tools in this source tree
- $ENV{PATH} = cwd . "/src:$ENV{PATH}";
- $ENV{CITRUN_SOCKET} = "test.socket";
- chdir $tmp_dir;
-
- write_file("one.c", <<EOF);
-#include <err.h>
-#include <signal.h>
-#include <stdlib.h>
-
-long long fib(long long);
-void print_output(long long);
-
-void
-usr1_sig(int signal)
-{
- exit(0);
-}
-
-int
-main(int argc, char *argv[])
-{
- struct sigaction sa;
- long long n;
-
- if (argc != 2)
- errx(1, "argc != 2");
-
- sa.sa_handler = &usr1_sig;
- sa.sa_flags = SA_RESTART;
- sigfillset(&sa.sa_mask);
- if (sigaction(SIGUSR1, &sa, NULL) == -1)
- err(1, "sigaction");
-
- n = atoi(argv[1]);
-
- print_output(fib(n));
- return 0;
-}
-EOF
-
- write_file("two.c", <<EOF);
-long long
-fib(long long n)
-{
- if (n == 0)
- return 0;
- else if (n == 1)
- return 1;
-
- return fib(n - 1) + fib(n - 2);
-}
-EOF
-
- write_file("three.c", <<EOF);
-#include <stdio.h>
-
-void
-print_output(long long n)
-{
- fprintf(stderr, "%lli", n);
- return;
-}
-EOF
-
- write_file("Jamfile", <<EOF);
-Main program : one.c two.c three.c ;
-EOF
-
- my $ret = system( "jam" );
- die "jam failed: $ret\n" if ($ret);
-
- return $self;
-}
-
-sub write_file {
- my ($name, $content) = @_;
- open( my $src_fh, ">", $name );
- print $src_fh $content;
- close( $src_fh );
-}
-
-sub run {
- my ($self, @args) = @_;
- $self->{pid} = open2(\*CHLD_OUT, undef, "program", @args);
-}
-
-sub kill {
- my ($self) = @_;
- kill 'USR1', $self->{pid};
-}
-
-sub wait {
- my ($self) = @_;
-
- waitpid( $self->{pid}, 0 );
- my $real_ret = $? >> 8;
-
- my $stderr;
- while (my $line = <CHLD_OUT>) {
- $stderr .= $line;
- }
-
- return ($real_ret, $stderr);
-}
-
-sub DESTROY {
- my ($self) = @_;
- $self->kill() if ($self->{pid});
-}
-
-1;
diff --git a/test/project.sh b/test/project.sh
@@ -0,0 +1,68 @@
+# exports TEST_TOOLS and puts us in a temporary directory.
+. test/utils.sh
+
+cat <<EOF > one.c
+#include <err.h>
+#include <signal.h>
+#include <stdlib.h>
+
+long long fib(long long);
+void print_output(long long);
+
+void
+usr1_sig(int signal)
+{
+ exit(0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct sigaction sa;
+ long long n;
+
+ if (argc != 2)
+ errx(1, "argc != 2");
+
+ sa.sa_handler = &usr1_sig;
+ sa.sa_flags = SA_RESTART;
+ sigfillset(&sa.sa_mask);
+ if (sigaction(SIGUSR1, &sa, NULL) == -1)
+ err(1, "sigaction");
+
+ n = atoi(argv[1]);
+
+ print_output(fib(n));
+ return 0;
+}
+EOF
+
+cat <<EOF > two.c
+long long
+fib(long long n)
+{
+ if (n == 0)
+ return 0;
+ else if (n == 1)
+ return 1;
+
+ return fib(n - 1) + fib(n - 2);
+}
+EOF
+
+cat <<EOF > three.c
+#include <stdio.h>
+
+void
+print_output(long long n)
+{
+ fprintf(stderr, "%lli", n);
+ return;
+}
+EOF
+
+cat <<EOF > Jamfile
+Main program : one.c two.c three.c ;
+EOF
+
+$TEST_TOOLS/citrun-wrap jam
diff --git a/test/utils.sh b/test/utils.sh
@@ -41,6 +41,16 @@ function check_diff
test_diff $test_num "$test_desc" check.good check.proc
}
+function filelist_diff
+{
+ test_num="${1}"
+ test_desc="source file (path, length) diff"
+
+ sort filelist.out > filelist.proc
+ test_diff $test_num "$test_desc" filelist.good filelist.proc
+ rm filelist.proc
+}
+
function test_diff
{
test_num=${1}