From: Gabe Black Date: Thu, 4 Feb 2021 06:28:24 +0000 (-0800) Subject: base,tests: Convert cprintftime from a "UnitTest" to a normal bin. X-Git-Tag: develop-gem5-snapshot~138 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8d92183669d8143d63d61f2e49d0b65dac88590e;p=gem5.git base,tests: Convert cprintftime from a "UnitTest" to a normal bin. This "UnitTest" was really not a unit test, it was a timing utility for measuring the performance of gem5's cprintf implementation. The name was misleading, but more than that, it was linked against all of gem5 which created a approximately 1.5 gigabyte binary for what is a very small program. Instead, the new version of cprintftime, which has the same functionality as the old version, weighs in at a svelte 500k with debug information. This also trims down the number of misleading "UnitTest" entries to 3, getting us closer to the point where we can eliminate that type of entity entirely. Change-Id: Id30d094f2844e948fe67e820c89412f8667aaa52 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40617 Maintainer: Gabe Black Maintainer: Jason Lowe-Power Tested-by: kokoro Reviewed-by: Daniel Carvalho Reviewed-by: Jason Lowe-Power --- diff --git a/src/base/SConscript b/src/base/SConscript index f8cd4ba07..1190b939e 100644 --- a/src/base/SConscript +++ b/src/base/SConscript @@ -39,6 +39,7 @@ Source('bmpwriter.cc') Source('channel_addr.cc') Source('cprintf.cc', add_tags='gtest lib') GTest('cprintf.test', 'cprintf.test.cc') +Executable('cprintftime', 'cprintftime.cc', 'cprintf.cc') Source('debug.cc') GTest('debug.test', 'debug.test.cc', 'debug.cc') if env['USE_FENV']: diff --git a/src/base/cprintftime.cc b/src/base/cprintftime.cc new file mode 100644 index 000000000..a09c4cb3b --- /dev/null +++ b/src/base/cprintftime.cc @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2002-2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include +#include + +#include "base/cprintf.hh" + +volatile int stop = false; + +void +handle_alarm(int signal) +{ + stop = true; +} + +void +do_test(int seconds) +{ + stop = false; + alarm(seconds); +} + +int +main() +{ + std::stringstream result; + int iterations = 0; + + signal(SIGALRM, handle_alarm); + + do_test(10); + while (!stop) { + std::stringstream result; + ccprintf(result, + "this is a %s of %d iterations %3.2f %p\n", + "test", iterations, 51.934, &result); + + iterations += 1; + } + + cprintf("completed %d iterations of ccprintf in 10s, %f iterations/s\n", + iterations, iterations / 10.0); + + do_test(10); + while (!stop) { + char result[1024]; + sprintf(result, + "this is a %s of %d iterations %3.2f %p\n", + "test", iterations, 51.934, &result); + + iterations += 1; + } + + cprintf("completed %d iterations of sprintf in 10s, %f iterations/s\n", + iterations, iterations / 10.0); + + return 0; +} diff --git a/src/unittest/SConscript b/src/unittest/SConscript index 19b254232..b0e29ed3f 100644 --- a/src/unittest/SConscript +++ b/src/unittest/SConscript @@ -30,7 +30,6 @@ Import('*') Source('unittest.cc') -UnitTest('cprintftime', 'cprintftime.cc') UnitTest('nmtest', 'nmtest.cc') stattest_py = PySource('m5', 'stattestmain.py', tags='stattest') diff --git a/src/unittest/cprintftime.cc b/src/unittest/cprintftime.cc deleted file mode 100644 index a09c4cb3b..000000000 --- a/src/unittest/cprintftime.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2002-2005 The Regents of The University of Michigan - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include -#include -#include -#include - -#include "base/cprintf.hh" - -volatile int stop = false; - -void -handle_alarm(int signal) -{ - stop = true; -} - -void -do_test(int seconds) -{ - stop = false; - alarm(seconds); -} - -int -main() -{ - std::stringstream result; - int iterations = 0; - - signal(SIGALRM, handle_alarm); - - do_test(10); - while (!stop) { - std::stringstream result; - ccprintf(result, - "this is a %s of %d iterations %3.2f %p\n", - "test", iterations, 51.934, &result); - - iterations += 1; - } - - cprintf("completed %d iterations of ccprintf in 10s, %f iterations/s\n", - iterations, iterations / 10.0); - - do_test(10); - while (!stop) { - char result[1024]; - sprintf(result, - "this is a %s of %d iterations %3.2f %p\n", - "test", iterations, 51.934, &result); - - iterations += 1; - } - - cprintf("completed %d iterations of sprintf in 10s, %f iterations/s\n", - iterations, iterations / 10.0); - - return 0; -}