Commit 837387a2 authored by Cristian Marussi's avatar Cristian Marussi Committed by Catalin Marinas

kselftest: arm64: extend test_init functionalities

Extend signal testing framework to allow the definition of a custom per
test initialization function to be run at the end of the common test_init
after test setup phase has completed and before test-run routine.

This custom per-test initialization function also enables the test writer
to decide on its own when forcibly skip the test itself using standard KSFT
mechanism.
Reviewed-by: default avatarDave Martin <Dave.Martin@arm.com>
Signed-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent c2820987
......@@ -19,11 +19,11 @@ int main(int argc, char *argv[])
current = &tde;
ksft_print_msg("%s :: %s\n", current->name, current->descr);
if (test_setup(current)) {
if (test_setup(current) && test_init(current)) {
test_run(current);
test_result(current);
test_cleanup(current);
}
test_result(current);
return current->pass ? KSFT_PASS : KSFT_FAIL;
return current->result;
}
......@@ -68,17 +68,20 @@ struct tdescr {
unsigned int timeout;
bool triggered;
bool pass;
unsigned int result;
/* optional sa_flags for the installed handler */
int sa_flags;
ucontext_t saved_uc;
/* optional test private data */
void *priv;
/* a custom setup function to be called before test starts */
/* a custom setup: called alternatively to default_setup */
int (*setup)(struct tdescr *td);
/* a custom init: called by default test init after test_setup */
bool (*init)(struct tdescr *td);
/* a custom cleanup function called before test exits */
void (*cleanup)(struct tdescr *td);
/* an optional function to be used as a trigger for test starting */
/* an optional function to be used as a trigger for starting test */
int (*trigger)(struct tdescr *td);
/*
* the actual test-core: invoked differently depending on the
......
......@@ -11,6 +11,8 @@
#include <linux/auxvec.h>
#include <ucontext.h>
#include <kselftest.h>
#include "test_signals.h"
#include "test_signals_utils.h"
#include "testcases/testcases.h"
......@@ -52,12 +54,18 @@ static void unblock_signal(int signum)
static void default_result(struct tdescr *td, bool force_exit)
{
if (td->pass)
if (td->result == KSFT_SKIP) {
fprintf(stderr, "==>> completed. SKIP.\n");
} else if (td->pass) {
fprintf(stderr, "==>> completed. PASS(1)\n");
else
td->result = KSFT_PASS;
} else {
fprintf(stdout, "==>> completed. FAIL(0)\n");
td->result = KSFT_FAIL;
}
if (force_exit)
exit(td->pass ? EXIT_SUCCESS : EXIT_FAILURE);
exit(td->result);
}
/*
......@@ -209,7 +217,7 @@ static inline int default_trigger(struct tdescr *td)
return !raise(td->sig_trig);
}
static int test_init(struct tdescr *td)
int test_init(struct tdescr *td)
{
td->minsigstksz = getauxval(AT_MINSIGSTKSZ);
if (!td->minsigstksz)
......@@ -236,7 +244,14 @@ static int test_init(struct tdescr *td)
~td->feats_supported));
}
/* Perform test specific additional initialization */
if (td->init && !td->init(td)) {
fprintf(stderr, "FAILED Testcase initialization.\n");
return 0;
}
td->initialized = 1;
fprintf(stderr, "Testcase initialized.\n");
return 1;
}
......@@ -248,9 +263,8 @@ int test_setup(struct tdescr *td)
assert(td->name);
assert(td->run);
if (!test_init(td))
return 0;
/* Default result is FAIL if test setup fails */
td->result = KSFT_FAIL;
if (td->setup)
return td->setup(td);
else
......@@ -271,7 +285,7 @@ int test_run(struct tdescr *td)
void test_result(struct tdescr *td)
{
if (td->check_result)
if (td->initialized && td->result != KSFT_SKIP && td->check_result)
td->check_result(td);
default_result(td, 0);
}
......
......@@ -6,6 +6,7 @@
#include "test_signals.h"
int test_init(struct tdescr *td);
int test_setup(struct tdescr *td);
void test_cleanup(struct tdescr *td);
int test_run(struct tdescr *td);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment