f/automatic-build-nightly
Jesse Vincent 4 years ago
parent 15ac6fe9e2
commit b05a8e8c5f
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -17,7 +17,6 @@ my $inside_test = 0;
my $test_class = 'GeneratedKTest';
GetOptions(
"cxx=s" => \$cxx_filename, # string
"ktest=s" => \$text_filename,
@ -36,15 +35,12 @@ else {
generate_test_file();
open(my $outfile, ">", $cxx_filename) || die "Can't open output file $!";
open( my $outfile, ">", $cxx_filename ) || die "Can't open output file $!";
print $outfile $cxx_output;
close ($outfile);
close($outfile);
exit(0);
sub load_from_text {
my @content = ();
open( my $text_fh, "<", $text_filename ) or die "Can't open file $!";
@ -76,7 +72,7 @@ sub load_from_text {
my $dispatcher = {
version => sub {
my $version = shift;
if ($version != 1) {
if ( $version != 1 ) {
die "This parser only supports v1";
}
return undef;
@ -104,7 +100,8 @@ sub load_from_text {
press => sub {
my $content = shift;
unless ( defined $named_switches->{$content} ) {
die "Attempt to press undefined switch $content on line $line_num";
die
"Attempt to press undefined switch $content on line $line_num";
}
return { switch => $content };
},
@ -118,10 +115,11 @@ sub load_from_text {
},
expect => sub {
my $content = shift;
if ( $content =~ /^no keyboard-report/) {
if ( $content =~ /^no keyboard-report/ ) {
return {
report_type => 'keyboard',
count => 0 };
count => 0
};
}
if ( $content =~ /^keyboard-report\s+(.*)$/ ) {
my $report_data = $1;
@ -150,9 +148,15 @@ sub load_from_text {
elsif ( $unit =~ /milli|ms/ ) {
return { millis => $count };
}
else { die "Line $line_num: failed to parse a 'run' clause: $content"; }
else {
die
"Line $line_num: failed to parse a 'run' clause: $content";
}
}
else {
die
"Line $line_num: failed to parse a 'run' clause: $content";
}
else { die "Line $line_num: failed to parse a 'run' clause: $content"; }
},
@ -161,8 +165,9 @@ sub load_from_text {
my $data;
if ( $type && exists $dispatcher->{$type} ) {
$data = $dispatcher->{$type}->($content);
# an empty return means "don't put it in the script
if (!$data) {
if ( !$data ) {
next;
}
}
@ -178,18 +183,16 @@ sub load_from_text {
}
close ($text_fh);
close($text_fh);
@script_lines = @content;
}
sub generate_test_file {
generate_preface();
generate_preface();
generate_key_addrs();
generate_script( );
generate_script();
generate_postscript();
@ -210,6 +213,7 @@ sub generate_key_addrs {
}
}
sub generate_start_new_test {
my $name = shift;
if ($inside_test) {
@ -220,6 +224,7 @@ sub generate_start_new_test {
indent();
cxx("ClearState(); // Clear any state from previous tests");
}
sub generate_end_test {
generate_check_expected_reports();
outdent();
@ -240,7 +245,9 @@ sub generate_script {
cxx('#define GTEST_COUT std::cerr << "[ INFO ] "');
generate_start_new_test('KtestSourceFilename');
cxx("GTEST_COUT << \"test: @{[File::Spec->rel2abs( $text_filename ) ]}\" << std::endl;");
cxx(
"GTEST_COUT << \"test: @{[File::Spec->rel2abs( $text_filename ) ]}\" << std::endl;"
);
generate_end_test('');
$reports_expected = 0;
@ -251,9 +258,13 @@ sub generate_script {
}
elsif ( my $action = $entry->{action} ) {
if ( $action eq 'name' ) { generate_start_new_test($entry->{data}->{test_name}) }
if ( $action eq 'name' ) {
generate_start_new_test( $entry->{data}->{test_name} );
}
elsif ( !$inside_test && defined $action ) {
die "Attempting to run an action '$action' when not inside a test section on line " . $entry->{line_num} . "\n";
die
"Attempting to run an action '$action' when not inside a test section on line "
. $entry->{line_num} . "\n";
}
elsif ( $action eq 'press' ) { generate_press($entry) }
elsif ( $action eq 'release' ) { generate_release($entry); }
@ -288,27 +299,33 @@ sub generate_press {
my $e = shift;
# TODO handle multuple presses
cxx( "PressKey(key_addr_" . $e->{data}->{switch} . ");" , $e->{comment});
cxx( "PressKey(key_addr_" . $e->{data}->{switch} . ");", $e->{comment} );
}
sub generate_release {
my $e = shift;
# TODO handle multiple releases
cxx( "ReleaseKey(key_addr_" . $e->{data}->{switch} . ");" , $e->{comment});
cxx( "ReleaseKey(key_addr_" . $e->{data}->{switch} . ");", $e->{comment} );
}
sub generate_expect_report {
my $report = shift;
if (! $report->{data}->{report_type} || $report->{data}->{report_type} ne 'keyboard') {
die "Don't know how to work with expectaions of reports other than 'keyboard' reports at line #".$report->{line_num}."\n";
if ( !$report->{data}->{report_type}
|| $report->{data}->{report_type} ne 'keyboard' )
{
die
"Don't know how to work with expectaions of reports other than 'keyboard' reports at line #"
. $report->{line_num} . "\n";
}
$reports_expected++;
if ($report->{data}->{count} == 0) {
cxx_comment($report->{comment});
cxx_comment("We don't expect any report here, and have told the tests to check that");
if ( $report->{data}->{count} == 0 ) {
cxx_comment( $report->{comment} );
cxx_comment(
"We don't expect any report here, and have told the tests to check that"
);
return;
}
@ -332,7 +349,7 @@ sub generate_check_expected_reports {
sub generate_preface {
my $preface = <<EOF;
my $preface = <<EOF;
#include "testing/setup-googletest.h"
#include "Kaleidoscope.h"
@ -354,22 +371,23 @@ namespace {
class @{[$test_class]} : public VirtualDeviceTest {};
EOF
for my $line (split/\n/,$preface) {
for my $line ( split /\n/, $preface ) {
cxx($line);
}
}
}
sub generate_postscript {
my $postscript = <<EOF;
my $postscript = <<EOF;
} // namespace
} // namespace testing
} // namespace kaleidoscope
EOF
for my $line (split/\n/,$postscript) {
for my $line ( split /\n/, $postscript ) {
cxx($line);
}
}
}
sub indent {

Loading…
Cancel
Save