/*************************************************************************** * Copyright (c) 2026 Eclipse ThreadX contributors * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * AI Disclosure: This file was largely AI-generated by Claude Code (Opus 5.5). * The AI-generated portions may be considered public domain (CC0-1.0) * and not subject to the project's licence. The human contributor has * reviewed and verified that the code is correct. * * SPDX-License-Identifier: MIT and CC0-1.0 **************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** ThreadX Test */ /** */ /** Module execution harness: protected module lifecycle */ /** */ /**************************************************************************/ /**************************************************************************/ /* A user-mode, memory-protected module is loaded, granted the shared area, started, left to exercise the kernel through its dispatcher, stopped and unloaded -- twice, so that the second cycle shows the first gave back what it took. The module must run unprivileged and must not fault. */ #include "harness_checks.h" #define LIFECYCLE_CYCLES ((ULONG) 2UL) #define MODULE_WAIT_TICKS ((ULONG) 500UL) #define PROTECTED_PROPERTIES ((ULONG) 0x02000007UL) /* GNU; user mode, memory protection, shared memory */ extern UCHAR module_services_protected[]; static TXM_MODULE_INSTANCE test_module; VOID harness_test(VOID) { ULONG cycle; ULONG available_before; harness_print("Module lifecycle: protected module, load/start/stop/unload twice\n"); available_before = harness_module_pool_available(); for (cycle = 1UL; cycle <= LIFECYCLE_CYCLES; cycle++) { harness_value("cycle", cycle); harness_shared_clear(); MODULE_SHARED[MODULE_IN_CYCLE] = cycle; harness_expect("memory load", (ULONG) txm_module_manager_memory_load(&test_module, "services protected", (VOID *) module_services_protected), (ULONG) TX_SUCCESS); harness_expect("module properties", test_module.txm_module_instance_property_flags, PROTECTED_PROPERTIES); harness_expect("shared area grant", (ULONG) harness_shared_grant(&test_module), (ULONG) TX_SUCCESS); harness_expect("module start", (ULONG) txm_module_manager_start(&test_module), (ULONG) TX_SUCCESS); harness_expect("module finished", (ULONG) harness_wait_for_module(MODULE_WAIT_TICKS), (ULONG) TX_TRUE); harness_check_services(cycle); harness_expect("module ran unprivileged", MODULE_SHARED[MODULE_OUT_CONTROL] & CONTROL_NPRIV, CONTROL_NPRIV); harness_expect("no memory fault", harness_fault_count, 0UL); harness_expect("module stop", (ULONG) txm_module_manager_stop(&test_module), (ULONG) TX_SUCCESS); harness_expect("module unload", (ULONG) txm_module_manager_unload(&test_module), (ULONG) TX_SUCCESS); harness_expect("module memory returned", harness_module_pool_available(), available_before); } }