-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added separate program to test stack trace [skip ci]
- Loading branch information
Showing
4 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Cppcheck - A tool for static C/C++ code analysis | ||
* Copyright (C) 2007-2023 Cppcheck team. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "stacktrace.h" | ||
|
||
// static functions are omitted from trace | ||
|
||
void my_func_2() | ||
{ | ||
print_stacktrace(stdout, 0, true, -1); | ||
} | ||
|
||
void my_func() | ||
{ | ||
my_func_2(); | ||
} | ||
|
||
int main(int argc, const char * const argv[]) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
//if (argc != 2) | ||
// return 1; | ||
|
||
my_func(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import subprocess | ||
import os | ||
import sys | ||
|
||
def _lookup_cppcheck_exe(exe_name): | ||
# path the script is located in | ||
script_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
if sys.platform == "win32": | ||
exe_name += ".exe" | ||
|
||
for base in (script_path + '/../../', './'): | ||
for path in ('', 'bin/', 'bin/debug/'): | ||
exe_path = base + path + exe_name | ||
if os.path.isfile(exe_path): | ||
print("using '{}'".format(exe_path)) | ||
return exe_path | ||
|
||
return None | ||
|
||
def _call_process(): | ||
exe = _lookup_cppcheck_exe('test-stacktrace') | ||
if exe is None: | ||
raise Exception('executable not found') | ||
p = subprocess.Popen([exe], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
comm = p.communicate() | ||
stdout = comm[0].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') | ||
stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') | ||
return p.returncode, stdout, stderr | ||
|
||
|
||
def test_stack(): | ||
exitcode, stdout, stderr = _call_process() | ||
assert stderr == '' | ||
lines = stdout.splitlines() | ||
assert lines[0] == 'Callstack:' | ||
assert lines[1].endswith('my_func_2()') | ||
assert lines[2].endswith('my_func()') |