Skip to content

Coverage test sys.settrace & improve coverage #17538

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

Closed
wants to merge 11 commits into from
Closed
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
32 changes: 15 additions & 17 deletions .github/workflows/ports_unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
# Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests.
# Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default.
with:
python-version: '3.11'
- name: Install packages
run: source tools/ci.sh && ci_unix_coverage_setup
- name: Build
Expand Down Expand Up @@ -169,23 +174,6 @@ jobs:
if: failure()
run: tests/run-tests.py --print-failures

settrace:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
# Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests.
# Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default.
with:
python-version: '3.11'
- name: Build
run: source tools/ci.sh && ci_unix_settrace_build
- name: Run main test suite
run: source tools/ci.sh && ci_unix_settrace_run_tests
- name: Print failures
if: failure()
run: tests/run-tests.py --print-failures

settrace_stackless:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -267,6 +255,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
# Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests.
# Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default.
with:
python-version: '3.11'
- name: Install packages
run: source tools/ci.sh && ci_unix_coverage_setup
- name: Build
Expand All @@ -287,6 +280,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
# Python 3.12 is the default for ubuntu-24.04, but that has compatibility issues with settrace tests.
# Can remove this step when ubuntu-latest uses a more recent Python 3.x as the default.
with:
python-version: '3.11'
- name: Install packages
run: source tools/ci.sh && ci_unix_coverage_setup
- name: Build
Expand Down
12 changes: 12 additions & 0 deletions ports/unix/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,24 @@ static mp_obj_t extra_coverage(void) {
fun_bc.context = &context;
fun_bc.child_table = NULL;
fun_bc.bytecode = (const byte *)"\x01"; // just needed for n_state
#if MICROPY_PY_SYS_SETTRACE
struct _mp_raw_code_t rc = {};
fun_bc.rc = &rc;
#endif
mp_code_state_t *code_state = m_new_obj_var(mp_code_state_t, state, mp_obj_t, 1);
code_state->fun_bc = &fun_bc;
code_state->ip = (const byte *)"\x00"; // just needed for an invalid opcode
code_state->sp = &code_state->state[0];
code_state->exc_sp_idx = 0;
code_state->old_globals = NULL;
#if MICROPY_STACKLESS
code_state->prev = NULL;
#endif
#if MICROPY_PY_SYS_SETTRACE
code_state->prev_state = NULL;
code_state->frame = NULL;
#endif

mp_vm_return_kind_t ret = mp_execute_bytecode(code_state, MP_OBJ_NULL);
mp_printf(&mp_plat_print, "%d %d\n", ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
}
Expand Down
1 change: 1 addition & 0 deletions ports/unix/variants/coverage/mpconfigvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

// Enable additional features.
#define MICROPY_DEBUG_PARSE_RULE_NAME (1)
#define MICROPY_PY_SYS_SETTRACE (1)
#define MICROPY_TRACKED_ALLOC (1)
#define MICROPY_WARNINGS_CATEGORY (1)
#undef MICROPY_VFS_ROM_IOCTL
Expand Down
2 changes: 1 addition & 1 deletion py/objcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static inline const void *mp_code_get_proto_fun(mp_obj_code_t *self) {

#include "py/emitglue.h"

#define MP_CODE_QSTR_MAP(context, idx) (context->constants.qstr_table[idx])
#define MP_CODE_QSTR_MAP(context, idx) ((qstr)(context->constants.qstr_table[idx]))

typedef struct _mp_obj_code_t {
// TODO this was 4 words
Expand Down
2 changes: 1 addition & 1 deletion py/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void frame_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
"<frame at 0x%p, file '%q', line %d, code %q>",
frame,
MP_CODE_QSTR_MAP(code->context, 0),
frame->lineno,
(int)frame->lineno,
MP_CODE_QSTR_MAP(code->context, prelude->qstr_block_name_idx)
);
}
Expand Down
6 changes: 6 additions & 0 deletions py/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ static inline void mp_thread_init_state(mp_state_thread_t *ts, size_t stack_size
ts->nlr_jump_callback_top = NULL;
ts->mp_pending_exception = MP_OBJ_NULL;

#if MICROPY_PY_SYS_SETTRACE
ts->prof_trace_callback = MP_OBJ_NULL;
ts->prof_callback_is_executing = false;
ts->current_code_state = NULL;
#endif

// If locals/globals are not given, inherit from main thread
if (locals == NULL) {
locals = mp_state_ctx.thread.dict_locals;
Expand Down
23 changes: 23 additions & 0 deletions tests/misc/sys_settrace_cov.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys

try:
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit


def trace_tick_handler(frame, event, arg):
print("FRAME", frame)
print("LASTI", frame.f_lasti)
return None


def f():
x = 3
return x


sys.settrace(trace_tick_handler)
f()
sys.settrace(None)
2 changes: 2 additions & 0 deletions tests/misc/sys_settrace_cov.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FRAME <frame at 0x\[0-9a-f\]\+, file '\.\*/sys_settrace_cov.py', line \\d\+, code f>
LASTI \\d\+
4 changes: 2 additions & 2 deletions tests/ports/unix/extra_coverage.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ argv atexit byteorder exc_info
executable exit getsizeof implementation
intern maxsize modules path
platform print_exception ps1
ps2 stderr stdin stdout
tracebacklimit version version_info
ps2 settrace stderr stdin
stdout tracebacklimit version version_info
ementation
# attrtuple
(start=1, stop=2, step=3)
Expand Down
3 changes: 2 additions & 1 deletion tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import tempfile

# Maximum time to run a PC-based test, in seconds.
TEST_TIMEOUT = 30
TEST_TIMEOUT = float(os.environ.get('MICROPY_TEST_TIMEOUT', 30))

# See stackoverflow.com/questions/2632199: __file__ nor sys.argv[0]
# are guaranteed to always work, this one should though.
Expand Down Expand Up @@ -354,6 +354,7 @@ def run_script_on_remote_target(pyb, args, test_file, is_special):
"micropython/meminfo.py",
"basics/bytes_compare3.py",
"basics/builtin_help.py",
"misc/sys_settrace_cov.py",
"thread/thread_exc2.py",
"ports/esp32/partition_ota.py",
)
Expand Down
29 changes: 6 additions & 23 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,6 @@ function ci_stm32_misc_build {
########################################################################################
# ports/unix

CI_UNIX_OPTS_SYS_SETTRACE=(
MICROPY_PY_BTREE=0
MICROPY_PY_FFI=0
MICROPY_PY_SSL=0
CFLAGS_EXTRA="-DMICROPY_PY_SYS_SETTRACE=1"
)

CI_UNIX_OPTS_SYS_SETTRACE_STACKLESS=(
MICROPY_PY_BTREE=0
MICROPY_PY_FFI=0
Expand Down Expand Up @@ -619,9 +612,9 @@ function ci_unix_standard_v2_run_tests {
}

function ci_unix_coverage_setup {
sudo pip3 install setuptools
sudo pip3 install pyelftools
sudo pip3 install ar
pip3 install setuptools
pip3 install pyelftools
pip3 install ar
gcc --version
python3 --version
}
Expand All @@ -632,7 +625,7 @@ function ci_unix_coverage_build {
}

function ci_unix_coverage_run_tests {
ci_unix_run_tests_full_helper coverage
MICROPY_TEST_TIMEOUT=60 ci_unix_run_tests_full_helper coverage
}

function ci_unix_coverage_run_mpy_merge_tests {
Expand Down Expand Up @@ -734,16 +727,6 @@ function ci_unix_float_clang_run_tests {
ci_unix_run_tests_helper CC=clang
}

function ci_unix_settrace_build {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/unix submodules
make ${MAKEOPTS} -C ports/unix "${CI_UNIX_OPTS_SYS_SETTRACE[@]}"
}

function ci_unix_settrace_run_tests {
ci_unix_run_tests_full_helper standard "${CI_UNIX_OPTS_SYS_SETTRACE[@]}"
}

function ci_unix_settrace_stackless_build {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/unix submodules
Expand All @@ -762,7 +745,7 @@ function ci_unix_sanitize_undefined_build {
}

function ci_unix_sanitize_undefined_run_tests {
ci_unix_run_tests_full_helper coverage "${CI_UNIX_OPTS_SANITIZE_UNDEFINED[@]}"
MICROPY_TEST_TIMEOUT=60 ci_unix_run_tests_full_helper coverage "${CI_UNIX_OPTS_SANITIZE_UNDEFINED[@]}"
}

function ci_unix_sanitize_address_build {
Expand All @@ -773,7 +756,7 @@ function ci_unix_sanitize_address_build {
}

function ci_unix_sanitize_address_run_tests {
ci_unix_run_tests_full_helper coverage "${CI_UNIX_OPTS_SANITIZE_ADDRESS[@]}"
MICROPY_TEST_TIMEOUT=60 ci_unix_run_tests_full_helper coverage "${CI_UNIX_OPTS_SANITIZE_ADDRESS[@]}"
}

function ci_unix_macos_build {
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy