summaryrefslogtreecommitdiff
path: root/shared/upytesthelper/upytesthelper.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-09-04 17:11:45 +1000
committerDamien George <damien@micropython.org>2024-09-19 13:31:36 +1000
commit067ef81cd0a59aac9027e26e0f8220e5074ec033 (patch)
treee80c35d6b7820f680edb4cfa5c3346e9d2bca802 /shared/upytesthelper/upytesthelper.c
parent5d8878b582b8b68d19ab02adfe32d683d5ea512f (diff)
all: Remove tinytest component.
With the recent qemu (d9a0fdda9a7b0db55c1115b55bb1b83cd5ce739c and 0426934969d06aa649ba903f5408cb331b5b9c2d) and zephyr (05cad7b56f5d460db26a468a05bfdeabe4a656db) changes to how their tests are run, two things became unused: - The tinytest framework, which embedded a set of tests and their expected output within firmware, so these tests could be run stand-alone. - The `--write-exp` and `--list-tests` options to `tests/run-tests.py`, which were needed primarily to generated the expected test output for tinytest (also the associated `tests/run-tests-exp.py/.sh` scripts are now unused). This commit removes the tinytest component and all its helper code. This eliminates a maintenance burden. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'shared/upytesthelper/upytesthelper.c')
-rw-r--r--shared/upytesthelper/upytesthelper.c137
1 files changed, 0 insertions, 137 deletions
diff --git a/shared/upytesthelper/upytesthelper.c b/shared/upytesthelper/upytesthelper.c
deleted file mode 100644
index ba20037f7..000000000
--- a/shared/upytesthelper/upytesthelper.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2017 Linaro Limited
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-#include <string.h>
-
-#include "py/mphal.h"
-#include "py/gc.h"
-#include "py/runtime.h"
-#include "py/compile.h"
-#include "upytesthelper.h"
-
-#if !MICROPY_PY_SYS_PATH
-#error "upytesthelper requires MICROPY_PY_SYS_PATH=1"
-#endif
-
-#if !MICROPY_PY_SYS_ARGV
-#error "upytesthelper requires MICROPY_PY_SYS_ARGV=1"
-#endif
-
-static const char *test_exp_output;
-static int test_exp_output_len, test_rem_output_len;
-static int test_failed;
-static void *heap_start, *heap_end;
-
-void upytest_set_heap(void *start, void *end) {
- heap_start = start;
- heap_end = end;
-}
-
-void upytest_set_expected_output(const char *output, unsigned len) {
- test_exp_output = output;
- test_exp_output_len = test_rem_output_len = len;
- test_failed = false;
-}
-
-bool upytest_is_failed(void) {
- if (test_failed) {
- return true;
- }
- #if 0
- if (test_rem_output_len != 0) {
- printf("remaining len: %d\n", test_rem_output_len);
- }
- #endif
- return test_rem_output_len != 0;
-}
-
-// MP_PLAT_PRINT_STRN() should be redirected to this function.
-// It will pass-through any content to mp_hal_stdout_tx_strn_cooked()
-// (the default value of MP_PLAT_PRINT_STRN), but will also match
-// it to the expected output as set by upytest_set_expected_output().
-// If mismatch happens, upytest_is_failed() returns true.
-void upytest_output(const char *str, mp_uint_t len) {
- if (!test_failed) {
- if (len > test_rem_output_len) {
- test_failed = true;
- } else {
- test_failed = memcmp(test_exp_output, str, len);
- #if 0
- if (test_failed) {
- printf("failed after char %u, within %d chars, res: %d\n",
- test_exp_output_len - test_rem_output_len, (int)len, test_failed);
- for (int i = 0; i < len; i++) {
- if (str[i] != test_exp_output[i]) {
- printf("%d %02x %02x\n", i, str[i], test_exp_output[i]);
- }
- }
- }
- #endif
- test_exp_output += len;
- test_rem_output_len -= len;
- }
- }
- mp_hal_stdout_tx_strn_cooked(str, len);
-}
-
-void upytest_execute_test(const char *src) {
- // To provide clean room for each test, interpreter and heap are
- // reinitialized before running each.
- gc_init(heap_start, heap_end);
- mp_init();
- mp_sys_path = mp_obj_new_list(0, NULL);
- #if MICROPY_MODULE_FROZEN
- mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__dot_frozen));
- #endif
- mp_obj_list_init(mp_sys_argv, 0);
-
- nlr_buf_t nlr;
- if (nlr_push(&nlr) == 0) {
- mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
- qstr source_name = lex->source_name;
- mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT);
- mp_obj_t module_fun = mp_compile(&parse_tree, source_name, false);
- mp_call_function_0(module_fun);
- nlr_pop();
- } else {
- mp_obj_t exc = (mp_obj_t)nlr.ret_val;
- if (mp_obj_is_subclass_fast(mp_obj_get_type(exc), &mp_type_SystemExit)) {
- // Assume that sys.exit() is called to skip the test.
- // TODO: That can be always true, we should set up convention to
- // use specific exit code as skip indicator.
- tinytest_set_test_skipped_();
- goto end;
- }
- mp_obj_print_exception(&mp_plat_print, exc);
- tt_abort_msg("Uncaught exception\n");
- }
-
- if (upytest_is_failed()) {
- tinytest_set_test_failed_();
- }
-
-end:
- mp_deinit();
-}