5#include "acpica_tests/all_tests.h"
22static uint64_t aml_tests_check_object_leak(
void)
32 LOG_ERR(
"memory leak detected, total objects %llu, but root has %llu children\n",
totalObjects, rootChildren);
45 LOG_ERR(
"test does not contain a valid _ERR object\n");
101static uint64_t aml_tests_acpica_do_test(
const acpica_test_t* test)
103 LOG_INFO(
"running test '%s'\n", test->name);
106 const uint8_t* end = (
const uint8_t*)testAml + testAml->header.length;
119 LOG_ERR(
"test '%s' failed to parse AML\n", test->name);
129 LOG_ERR(
"test '%s' does not contain a valid SETN object\n", test->name);
137 LOG_ERR(
"test '%s' failed to set SETN value\n", test->name);
148 LOG_ERR(
"test '%s' does not contain a valid method\n", test->name);
157 LOG_ERR(
"test '%s' method evaluation failed\n", test->name);
167 LOG_ERR(
"test '%s' method did not return an integer\n", test->name);
177 LOG_INFO(
"test '%s' passed\n", test->name);
181static uint64_t aml_tests_acpica_run_all(
void)
188 for (
uint32_t i = 0; i < ACPICA_TEST_COUNT; i++)
190 const acpica_test_t* test = &acpicaTests[i];
191 if (aml_tests_acpica_do_test(test) ==
ERR)
203 LOG_INFO(
"running post init tests\n");
208 if (aml_tests_acpica_run_all() ==
ERR)
212 LOG_WARN(
"ACPICA tests failed, this is expected until more AML features are implemented\n");
218 aml_tests_perf_report();
222 LOG_ERR(
"memory leak detected, total objects before test %llu, after test %llu\n", startingObjects,
231uint64_t aml_tests_post_parse_all(
void)
233 if (aml_tests_check_object_leak() ==
ERR)
238 LOG_INFO(
"post parse all tests passed\n");
248} aml_perf_stack_entry_t;
261 aml_perf_stack_entry_t* entry =
malloc(
sizeof(aml_perf_stack_entry_t));
264 LOG_ERR(
"Performance profiler stack allocation failed\n");
269 entry->token = token->
num;
271 entry->childTime = 0;
275 tokenOccurrences[token->
num]++;
278void aml_tests_perf_end(
void)
282 LOG_ERR(
"Performance profiler stack underflow\n");
289 clock_t exclusiveTime = (entry->childTime >= totalTime) ? 0 : (totalTime - entry->childTime);
292 timeTakenPerToken[entry->token] += exclusiveTime;
297 aml_perf_stack_entry_t* perfStackTop =
CONTAINER_OF(
list_last(&perfStack), aml_perf_stack_entry_t, entry);
298 perfStackTop->childTime += totalTime;
304void aml_tests_perf_report(
void)
308 LOG_WARN(
"Performance report called with %d unclosed measurements\n",
list_length(&perfStack));
327 if (timeTakenPerToken[i] > 0)
329 sorted[
count].tokenNum = i;
330 sorted[
count].time = timeTakenPerToken[i];
337 token_time_pair_t key = sorted[i];
340 while (j >= 0 && sorted[j].
time < key.time)
342 sorted[j + 1] = sorted[j];
353 sorted[i].
time / tokenOccurrences[sorted[i].tokenNum]);
358 timeTakenPerToken[i] = 0;
uint64_t aml_term_list_read(aml_state_t *state, aml_object_t *scope, const uint8_t *start, const uint8_t *end, aml_term_list_ctx_t *parentCtx)
Reads a TermList structure from the AML byte stream.
const char * aml_exception_to_string(aml_exception_t code)
Converts an AML exception code to a string.
void aml_exception_unregister(aml_exception_handler_t handler)
Unregisters an AML exception handler.
uint64_t aml_exception_register(aml_exception_handler_t handler)
Registers an AML exception handler.
aml_exception_t
AML exception codes.
aml_object_t * aml_method_evaluate(aml_state_t *parentState, aml_method_obj_t *method, aml_object_t **args)
Evaluate a method with the given arguments.
aml_object_t * aml_namespace_find(aml_namespace_overlay_t *overlay, aml_object_t *start, uint64_t nameCount,...)
Find an object in the namespace heirarchy by name segments.
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
aml_object_t * aml_namespace_get_root(void)
Get the root object of the namespace heirarchy.
uint64_t aml_integer_set(aml_object_t *object, aml_integer_t value)
Set a object as an integer with the given value and bit width.
uint64_t aml_object_count_children(aml_object_t *parent)
Recursively count how many children an object has.
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
uint64_t aml_string_set(aml_object_t *object, const char *str)
Set a object as a string with the given value.
uint64_t aml_object_get_total_count(void)
Get the total amount of allocated ACPI objects.
uint64_t aml_state_init(aml_state_t *state, aml_object_t **args)
Initialize an AML state.
void aml_state_deinit(aml_state_t *state)
Deinitialize an AML state.
const char * aml_type_to_string(aml_type_t type)
Convert an aml data type to a string.
aml_token_num_t
Token numbers.
static const aml_token_props_t * aml_token_lookup(aml_token_num_t num)
Lookup token properties.
#define LOG_ERR(format,...)
#define LOG_WARN(format,...)
#define LOG_INFO(format,...)
clock_t timer_uptime(void)
Time since boot.
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
static uint64_t list_length(list_t *list)
Gets the length of the list.
static list_entry_t * list_last(list_t *list)
Gets the last entry in the list without removing it.
#define LIST_CREATE(name)
Creates a list initializer.
static void list_push(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static list_entry_t * list_pop(list_t *list)
Pops the first entry from the list.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
__UINT64_TYPE__ clock_t
A nanosecond time.
static uint64_t totalObjects
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
aml_integer_obj_t integer
aml_namespace_overlay_t overlay
Holds any named objects created during parsing.
A entry in a doubly linked list.
Secondary System Description Table.
_PUBLIC time_t time(time_t *timer)