-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autotest: add autotest framework for utility unit tests #348
Conversation
Makefile.am
Outdated
@@ -40,6 +40,7 @@ noinst_LIBRARIES = # Static libraries built | |||
noinst_PROGRAMS = # Binaries built that are not installed | |||
BUILT_SOURCES = # Generated source files | |||
TESTS = # Tests to execute | |||
EXTRA_DIST = # ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document this.
tests/helloworld.at
Outdated
AT_SETUP([p4c]) | ||
|
||
m4_define([P4C_CHECK], [ | ||
AT_CHECK([p4c -t tofino min.p4], [1], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no p4c binary in the public repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am working on a compiler driver called p4c which is analogous to clang or gcc. I will push the code for p4c before this PR goes in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should write a document describing what the compiler driver is supposed to do.
This code is really the infrastructure for building a family of compilers, one for each target. Since we don't know the needs of each target, I am not sure whether it's easy to create a driver common to all targets.
* .... | ||
* } | ||
* | ||
* P4CTEST_REGISTER("my-test", my_test_main); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about REGISTER taking just one argument? The string should be generated from the test name; perhaps you can always append _main as well.
@@ -0,0 +1,89 @@ | |||
# Copyright 2013-present Barefoot Networks, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know how this autotest stuff works, and I am trying to avoid learning if possible.
It would be nice if the extensions/ folder was used for testing as well - so you can actually "merge" the tests here with whatever tests/ folders may exist in any extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an example in backend/p4test/tests to show how to extend unit test with custom backend.
tests/p4ctest.cpp
Outdated
} | ||
|
||
static void | ||
add_command(struct p4c_cmdl_command* cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the style guide would require opening brace on the previous line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
tests/p4ctest.cpp
Outdated
#include "lib/error.h" | ||
#include "p4ctest.h" | ||
|
||
static std::vector<p4c_cmdl_command*> commands; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not package all of these in a class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
tests/p4ctest.cpp
Outdated
exit(1); | ||
} | ||
if (ferror(stderr)) { | ||
std::cerr << "write to stderr failed" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this expected to succeed? Probably it does not matter.
tests/p4ctest.h
Outdated
struct p4c_cmdl_command { | ||
const char *name; | ||
const char *usage; | ||
int min_args; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how these are used.
c46815c
to
12f3d4b
Compare
@ChrisDodd @mbudiu-vmw This patch is ready for review. |
ceb4b87
to
e31cb45
Compare
tests/p4ctest.h
Outdated
/* Overview | ||
* ======== | ||
* | ||
* P4C tests directory contains many small test programs. One down side |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this comment should not describe the history of the program creation, it should just say what the program does. This information should be in the pull request, but not in a comment - it will become obsolete after a while.
tests/ir.at
Outdated
@@ -0,0 +1,22 @@ | |||
AT_BANNER([intermediate representation unit tests]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that users writing tests won't have to learn this language...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m4 syntax takes some getting used to, particularly the automake dialect of it.
This still defines the same macro mulitple times with different names (just once in each file) -- might it make more sense to call it P4TEST_TEST_RUN
or (something less verbose) and put it in the top level file (testsuite.at?) That way each sub .at file is just a list of tests.
configure.ac
Outdated
AM_INIT_AUTOMAKE([foreign subdir-objects 1.14]) | ||
AM_SILENT_RULES([yes]) | ||
AM_SILENT_RULES([no]) | ||
AM_MISSING_PROG([AUTOM4TE], [autom4te]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I much prefer silent rules as it makes it easier to see compiler warnings (not buried in masses of libtool invokation cruft). Using V=1 is usually adequate for debugging make problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
tests/p4ctest.h
Outdated
* all test programs into a single program, p4c-test. Regardless of | ||
* the number of test programs, linking will be done only once to produce | ||
* p4ctest. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much time does this actually save? Each little program only take about .3 seconds to link on my machine, so it seems unlike to save more that a second or two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed comments.
tests/ir.at
Outdated
AT_CHECK([p4ctest $2], [0], [stdout], []) | ||
AT_CLEANUP] | ||
) | ||
TEST_IR_OPEQ([ir - transform ], [test-transform]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a lot of boilerplate -- why define a new TEST_XXX macro for each test that you then invoke once, particularly since they're all the same. Why not just a single macro invoked mulitple times (once for each test).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
fcc3135
to
d360b25
Compare
Removed /unittests, divided existing unit tests into: ir, frontend and util groups.
ff7b3e0
to
801be33
Compare
@ChrisDodd How about the following usage? make check D=1 // for enabling -gdb debugging I can try to generate a simplified version of testsuite.log file that only contains information about the failed cases, and save the info in test-suite.log I can print the command to rerun a test case as part of the log output, so you can click on the string and copy/paste to terminal. Let me know if there are more options you would like to have. |
For -j, you probably need a long name so it doesn't collide with other things; most people will just want to set it in their .bashrc file and always have it 'just work'. That's the way V=1 is going to collide with the existing use of How do you run a particular test by name? How do you know what "test 47" is -- how do you find the source and intermediate files of the test so you can figure out what went wrong? |
@hanw: isn't it just a matter of propagating $MAKEFLAGS to the make commands to the testsuite command?
|
I am able to make these to work. but not these two. In the second case, MAKEFLAGS has a value of "-j --jobserver-fds=4,5", instead of what I set on command line (-j8). not sure where it comes from. |
tests/Makefile.am
Outdated
"$$@" || (test X'$(RECHECK)' = Xyes && "$$@" --recheck) | ||
|
||
check-bmv2: | ||
make check-local TESTSUITEFLAGS='-k bmv2 $(filter-out $@,$(MAKECMDGOALS))' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tried passing $(MAKEFLAGS) to this command? That is:
check-bmv2:
make check-local TESTSUITEFLAGS='-k bmv2 $(filter-out $@,$(MAKECMDGOALS))' $(MAKEFLAGS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This turns out to be a known issue in make 4.1, where the value N in -jN is not passed down to MAKEFLAGS. I installed make 4.2.1 from source, and problem solved.
@ChrisDodd, to run a particular test, we can use the name of the p4 program as keyword. In addition, -v will print all commands and stdout/stderr from running the test case: |
We can also narrow down the test case by specifying the name of the test group, e.g.: make check-local TESTSUITEFLAGS="-k tofino,switch.p4 -v" |
-j2 is the default setting on travis
We don't have a framework for testing utility tools, such as compiler driver. Here is an attempt to add support for autotest framework.
@ChrisDodd Can you take a look and let me know if you are okay with the approach?