Skip to content
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

Issue194 templated functions #236

Merged
merged 7 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/flitcli/flit_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ def extract_symbols(file_or_filelist, objdir):
# generate the symbol tuples
for symbol_string, demangled_string in zip(symbol_strings,
demangled_symbol_strings):
symbol = symbol_string.split(maxsplit=2)[2]
symbol_type, symbol = symbol_string.split(maxsplit=2)[1:]
if symbol_type != "T": # only look at strong symbols in the text section
continue
demangled = demangled_string.split(maxsplit=2)[2]
try:
deffile, defline = symbol_line_mapping[symbol]
Expand Down
3 changes: 2 additions & 1 deletion tests/flit_cli/flit_bisect/data/tests/BisectTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "file1.h"
#include "file2.h"
#include "file3.h"
#include "file4.h"

#include <flit.h>

Expand All @@ -105,7 +106,7 @@ class BisectTest : public flit::TestBase<T> {
protected:
virtual flit::Variant run_impl(const std::vector<T> &ti) override {
FLIT_UNUSED(ti);
return file1_all() + file2_all() + file3_all();
return file1_all() + file2_all() + file3_all() + file4_all();
}

protected:
Expand Down
114 changes: 114 additions & 0 deletions tests/flit_cli/flit_bisect/data/tests/file4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* -- LICENSE BEGIN --
*
* Copyright (c) 2015-2018, Lawrence Livermore National Security, LLC.
*
* Produced at the Lawrence Livermore National Laboratory
*
* Written by
* Michael Bentley (mikebentley15@gmail.com),
* Geof Sawaya (fredricflinstone@gmail.com),
* and Ian Briggs (ian.briggs@utah.edu)
* under the direction of
* Ganesh Gopalakrishnan
* and Dong H. Ahn.
*
* LLNL-CODE-743137
*
* All rights reserved.
*
* This file is part of FLiT. For details, see
* https://pruners.github.io/flit
* Please also read
* https://github.com/PRUNERS/FLiT/blob/master/LICENSE
*
* 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 disclaimer below.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* (as noted below) in the documentation and/or other materials
* provided with the distribution.
*
* - Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL
* SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY 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.
*
* Additional BSD Notice
*
* 1. This notice is required to be provided under our contract
* with the U.S. Department of Energy (DOE). This work was
* produced at Lawrence Livermore National Laboratory under
* Contract No. DE-AC52-07NA27344 with the DOE.
*
* 2. Neither the United States Government nor Lawrence Livermore
* National Security, LLC nor any of their employees, makes any
* warranty, express or implied, or assumes any liability or
* responsibility for the accuracy, completeness, or usefulness of
* any information, apparatus, product, or process disclosed, or
* represents that its use would not infringe privately-owned
* rights.
*
* 3. Also, reference herein to any specific commercial products,
* process, or services by trade name, trademark, manufacturer or
* otherwise does not necessarily constitute or imply its
* endorsement, recommendation, or favoring by the United States
* Government or Lawrence Livermore National Security, LLC. The
* views and opinions of authors expressed herein do not
* necessarily state or reflect those of the United States
* Government or Lawrence Livermore National Security, LLC, and
* shall not be used for advertising or product endorsement
* purposes.
*
* -- LICENSE END --
*/

#include "file4.h"

#include <flit.h>

#include <string>

int file4_func1() { return 1; }
int file4_func2() { return 2; }
int file4_func3() { return 3; }
int file4_func4() { return 4; }

template<int i>
int file4_func5_TEMPLATE_PROBLEM() {
if (std::string(FLIT_OPTL) == "-O3") {
return 5 + 10; // variability introduced = 10
} else {
return 5;
}
}



int file4_all() {
return file4_func1()
+ file4_func2()
+ file4_func3()
+ file4_func4()
+ file4_func5_TEMPLATE_PROBLEM<0>()
+ file4_func5_TEMPLATE_PROBLEM<1>()
+ file4_func5_TEMPLATE_PROBLEM<2>();
}
95 changes: 95 additions & 0 deletions tests/flit_cli/flit_bisect/data/tests/file4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* -- LICENSE BEGIN --
*
* Copyright (c) 2015-2018, Lawrence Livermore National Security, LLC.
*
* Produced at the Lawrence Livermore National Laboratory
*
* Written by
* Michael Bentley (mikebentley15@gmail.com),
* Geof Sawaya (fredricflinstone@gmail.com),
* and Ian Briggs (ian.briggs@utah.edu)
* under the direction of
* Ganesh Gopalakrishnan
* and Dong H. Ahn.
*
* LLNL-CODE-743137
*
* All rights reserved.
*
* This file is part of FLiT. For details, see
* https://pruners.github.io/flit
* Please also read
* https://github.com/PRUNERS/FLiT/blob/master/LICENSE
*
* 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 disclaimer below.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the disclaimer
* (as noted below) in the documentation and/or other materials
* provided with the distribution.
*
* - Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL
* SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY 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.
*
* Additional BSD Notice
*
* 1. This notice is required to be provided under our contract
* with the U.S. Department of Energy (DOE). This work was
* produced at Lawrence Livermore National Laboratory under
* Contract No. DE-AC52-07NA27344 with the DOE.
*
* 2. Neither the United States Government nor Lawrence Livermore
* National Security, LLC nor any of their employees, makes any
* warranty, express or implied, or assumes any liability or
* responsibility for the accuracy, completeness, or usefulness of
* any information, apparatus, product, or process disclosed, or
* represents that its use would not infringe privately-owned
* rights.
*
* 3. Also, reference herein to any specific commercial products,
* process, or services by trade name, trademark, manufacturer or
* otherwise does not necessarily constitute or imply its
* endorsement, recommendation, or favoring by the United States
* Government or Lawrence Livermore National Security, LLC. The
* views and opinions of authors expressed herein do not
* necessarily state or reflect those of the United States
* Government or Lawrence Livermore National Security, LLC, and
* shall not be used for advertising or product endorsement
* purposes.
*
* -- LICENSE END --
*/

#ifndef FILE4_H
#define FILE4_H

int file4_func1();
int file4_func2();
int file4_func3();
int file4_func4();
template <int i>
int file4_func5_TEMPLATE_PTOBLEM(); // variability = 10
int file4_all();

#endif // FILE4_H
29 changes: 21 additions & 8 deletions tests/flit_cli/flit_bisect/tst_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@
... outstream=ostream)
... bisect_out = ostream.getvalue().splitlines()
... with open(os.path.join(temp_dir, 'bisect-01', 'bisect.log')) as fin:
... log_contents = fin.readlines()
... raw_log = fin.readlines()
... stripped_log = [line[line.index(' bisect:')+8:].rstrip()
... for line in raw_log]
... log_contents = [line for line in stripped_log if line.strip() != '']

Verify the output of flit init
>>> print('\\n'.join(init_out)) # doctest:+ELLIPSIS
Expand All @@ -126,29 +129,31 @@
Verify that all source files were found and output during the search
>>> sorted([x.split(':')[0].split()[-1] for x in bisect_out
... if x.startswith(' Found differing source file')])
['tests/file1.cpp', 'tests/file2.cpp', 'tests/file3.cpp']
['tests/file1.cpp', 'tests/file2.cpp', 'tests/file3.cpp', 'tests/file4.cpp']

Verify that the three differing sources were output in the "differing sources:"
Verify that the four differing sources were output in the "differing sources:"
section
>>> idx = bisect_out.index('all variability inducing source file(s):')
>>> print('\\n'.join(bisect_out[idx+1:idx+4]))
>>> print('\\n'.join(bisect_out[idx+1:idx+5]))
tests/file4.cpp (score 30.0)
tests/file1.cpp (score 10.0)
tests/file2.cpp (score 7.0)
tests/file3.cpp (score 4.0)
>>> bisect_out[idx+4].startswith('Searching for differing symbols in:')
>>> bisect_out[idx+5].startswith('Searching for differing symbols in:')
True

Verify that all three files were searched individually
Verify that all four files were searched individually
>>> sorted([x.split()[-1] for x in bisect_out
... if x.startswith('Searching for differing symbols in:')])
['tests/file1.cpp', 'tests/file2.cpp', 'tests/file3.cpp']
['tests/file1.cpp', 'tests/file2.cpp', 'tests/file3.cpp', 'tests/file4.cpp']

Verify all functions were identified during the symbol searches
Verify all non-templated functions were identified during the symbol searches
>>> print('\\n'.join(
... sorted([' '.join(x.split()[-6:]) for x in bisect_out
... if x.startswith(' Found differing symbol on line')])))
line 100 -- file1_func3_PROBLEM() (score 2.0)
line 103 -- file3_func5_PROBLEM() (score 3.0)
line 106 -- file4_all() (score 30.0)
line 108 -- file1_func4_PROBLEM() (score 3.0)
line 91 -- file2_func1_PROBLEM() (score 7.0)
line 92 -- file1_func2_PROBLEM() (score 5.0)
Expand Down Expand Up @@ -178,9 +183,17 @@
>>> bisect_out[idx+3].startswith(' ')
False

Verify the bad symbols section for file4.cpp
>>> idx = bisect_out.index(' All differing symbols in tests/file4.cpp:')
>>> print('\\n'.join(sorted(bisect_out[idx+1:idx+2])))
line 106 -- file4_all() (score 30.0)
>>> bisect_out[idx+2].startswith(' ')
False

Test the All differing symbols section of the output
>>> idx = bisect_out.index('All variability inducing symbols:')
>>> print('\\n'.join(bisect_out[idx+1:])) # doctest:+ELLIPSIS
/.../tests/file4.cpp:106 ... -- file4_all() (score 30.0)
/.../tests/file2.cpp:91 ... -- file2_func1_PROBLEM() (score 7.0)
/.../tests/file1.cpp:92 ... -- file1_func2_PROBLEM() (score 5.0)
/.../tests/file1.cpp:108 ... -- file1_func4_PROBLEM() (score 3.0)
Expand Down
2 changes: 2 additions & 0 deletions tests/flit_cli/flit_bisect/tst_bisect_biggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
... 'tests/file1.cpp': 10.0,
... 'tests/file2.cpp': 7.0,
... 'tests/file3.cpp': 4.0,
... 'tests/file4.cpp': 0.0,
... }

>>> all_symbol_scores = {
Expand All @@ -136,6 +137,7 @@
... create_symbol(3, 3, 100, False): 0.0,
... create_symbol(3, 4, 101, False): 0.0,
... create_symbol(3, 5, 103, True): 3.0,
... create_symbol(4, 1, 103, False): 0.0,
... }

>>> def build_bisect_stub(makepath, directory, target='bisect', verbose=False,
Expand Down