gitlab.arm.com will be in the maintainance mode on Wednesday June 29th 01:00 - 10:00 (UTC+1). Repositories is read only during the maintainance.

Commit e7c68b43 authored by Andrew Jones's avatar Andrew Jones
Browse files

lib: share arm-selftest utility functions



arm-selftest has a couple utility functions that could be useful
to other unit tests, even other architectures. So move them out.
split_var moves to lib/util, where we can add other random
utilities over time. assert_args inspires report_abort, which
allows us to report a message, using the current prefix, that
we're aborting (outputs ABORT vs. PASS/FAIL). This is useful
for cases when unit tests can't complete due to missing
dependencies of some sort, such as missing/invalid inputs from
the user.
Signed-off-by: Andrew Jones's avatarAndrew Jones <drjones@redhat.com>
Reviewed-by: default avatarThomas Huth <thuth@redhat.com>
Tested-by: default avatarLaurent Vivier <lvivier@redhat.com>
Reviewed-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
parent cb12eccc
......@@ -6,6 +6,7 @@
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
#include <libcflat.h>
#include <util.h>
#include <alloc.h>
#include <devicetree.h>
#include <asm/setup.h>
......@@ -18,43 +19,21 @@
#include <asm/cpumask.h>
#include <asm/barrier.h>
static void assert_args(int num_args, int needed_args)
{
if (num_args < needed_args) {
printf("selftest: not enough arguments\n");
abort();
}
}
static char *split_var(char *s, long *val)
{
char *p;
p = strchr(s, '=');
if (!p)
return NULL;
*val = atol(p+1);
*p = '\0';
return s;
}
static void check_setup(int argc, char **argv)
{
int nr_tests = 0, i;
char *var;
int nr_tests = 0, len, i;
long val;
for (i = 0; i < argc; ++i) {
var = split_var(argv[i], &val);
if (!var)
len = parse_keyval(argv[i], &val);
if (len == -1)
continue;
report_prefix_push(var);
argv[i][len] = '\0';
report_prefix_push(argv[i]);
if (strcmp(var, "mem") == 0) {
if (strcmp(argv[i], "mem") == 0) {
phys_addr_t memsize = PHYS_END - PHYS_OFFSET;
phys_addr_t expected = ((phys_addr_t)val)*1024*1024;
......@@ -63,7 +42,7 @@ static void check_setup(int argc, char **argv)
memsize/1024/1024);
++nr_tests;
} else if (strcmp(var, "smp") == 0) {
} else if (strcmp(argv[i], "smp") == 0) {
report("nr_cpus = %d", nr_cpus == (int)val, nr_cpus);
++nr_tests;
......@@ -72,7 +51,8 @@ static void check_setup(int argc, char **argv)
report_prefix_pop();
}
assert_args(nr_tests, 2);
if (nr_tests < 2)
report_abort("missing input");
}
static struct pt_regs expected_regs;
......@@ -343,7 +323,10 @@ static void cpu_report(void)
int main(int argc, char **argv)
{
report_prefix_push("selftest");
assert_args(argc, 1);
if (!argc)
report_abort("no test specified");
report_prefix_push(argv[0]);
if (strcmp(argv[0], "setup") == 0) {
......
......@@ -27,6 +27,7 @@ CFLAGS += -I lib -I lib/libfdt
asm-offsets = lib/$(ARCH)/asm-offsets.h
include config/asm-offsets.mak
cflatobjs += lib/util.o
cflatobjs += lib/alloc.o
cflatobjs += lib/devicetree.o
cflatobjs += lib/virtio.o
......
......@@ -58,11 +58,12 @@ extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
extern int vprintf(const char *fmt, va_list va);
extern long atol(const char *ptr);
void report_prefix_push(const char *prefix);
void report_prefix_pop(void);
void report(const char *msg_fmt, bool pass, ...);
void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...);
int report_summary(void);
extern void report_prefix_push(const char *prefix);
extern void report_prefix_pop(void);
extern void report(const char *msg_fmt, bool pass, ...);
extern void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...);
extern void report_abort(const char *msg_fmt, ...);
extern int report_summary(void);
#define ARRAY_SIZE(_a) (sizeof(_a)/sizeof((_a)[0]))
......
......@@ -94,3 +94,17 @@ int report_summary(void)
spin_unlock(&lock);
}
void report_abort(const char *msg_fmt, ...)
{
va_list va;
puts("ABORT: ");
puts(prefixes);
va_start(va, msg_fmt);
vprintf(msg_fmt, va);
va_end(va);
puts("\n");
report_summary();
abort();
}
/*
* Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
#include <libcflat.h>
int parse_keyval(char *s, long *val)
{
char *p;
p = strchr(s, '=');
if (!p)
return -1;
*val = atol(p+1);
return p - s;
}
#ifndef _UTIL_H_
#define _UTIL_H_
/*
* Collection of utility functions to share between unit tests.
*
* Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.
*/
/*
* parse_keyval extracts the integer from a string formatted as
* string=integer. This is useful for passing expected values to
* the unit test on the command line, i.e. it helps parse QEMU
* command lines that include something like -append var1=1 var2=2
* @s is the input string, likely a command line parameter, and
* @val is a pointer to where the integer will be stored.
*
* Returns the offset of the '=', or -1 if no keyval pair is found.
*/
extern int parse_keyval(char *s, long *val);
#endif
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