Commit 4494052a authored by Daniel Vetter's avatar Daniel Vetter

lib/tests: Add header for common helpers

Start with internal_assert, more will follow. While at it, use
internal_assert everywhere (except where we check exit status, those
will get dedicated assert checks).
Reviewed-by: Arkadiusz Hiler's avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
Signed-off-by: Daniel Vetter's avatarDaniel Vetter <daniel.vetter@intel.com>
parent 4d0d81a2
......@@ -22,7 +22,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
......@@ -36,13 +35,7 @@
#include "igt_core.h"
/*
* We need to hide assert from the cocci igt test refactor spatch.
*
* IMPORTANT: Test infrastructure tests are the only valid places where using
* assert is allowed.
*/
#define internal_assert assert
#include "igt_tests_common.h"
char test[] = "test";
char *argv_run[] = { test };
......
......@@ -22,23 +22,23 @@
*
*/
#include <assert.h>
#include "igt_core.h"
#include "igt_tests_common.h"
igt_main
{
assert(igt_can_fail() == false);
internal_assert(igt_can_fail() == false);
igt_fixture {
assert(igt_can_fail());
internal_assert(igt_can_fail());
}
assert(igt_can_fail() == false);
internal_assert(igt_can_fail() == false);
igt_subtest("subtest") {
assert(igt_can_fail());
internal_assert(igt_can_fail());
}
assert(igt_can_fail() == false);
internal_assert(igt_can_fail() == false);
}
......@@ -22,11 +22,11 @@
*
*/
#include <assert.h>
#include "igt_core.h"
#include "igt_tests_common.h"
igt_simple_main
{
assert(igt_can_fail());
internal_assert(igt_can_fail());
}
......@@ -21,19 +21,20 @@
* IN THE SOFTWARE.
*/
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "igt_core.h"
#include "igt_tests_common.h"
int test;
int pipes[2];
static void exit_handler1(int sig)
{
assert(test == 1);
internal_assert(test == 1);
test++;
}
......@@ -42,12 +43,12 @@ static void exit_handler2(int sig)
char tmp = 1;
/* ensure exit handlers are called in reverse */
assert(test == 0);
internal_assert(test == 0);
test++;
/* we need to get a side effect to the parent to make sure exit handlers
* actually run. */
assert(write(pipes[1], &tmp, 1) == 1);
internal_assert(write(pipes[1], &tmp, 1) == 1);
}
enum test_type {
......@@ -67,7 +68,7 @@ static int testfunc(enum test_type test_type)
int status;
char tmp = 0;
assert(pipe2(pipes, O_NONBLOCK) == 0);
internal_assert(pipe2(pipes, O_NONBLOCK) == 0);
pid = fork();
......@@ -100,10 +101,10 @@ static int testfunc(enum test_type test_type)
igt_exit();
}
assert(waitpid(pid, &status, 0) != -1);
internal_assert(waitpid(pid, &status, 0) != -1);
assert(read(pipes[0], &tmp, 1) == 1);
assert(tmp == 1);
internal_assert(read(pipes[0], &tmp, 1) == 1);
internal_assert(tmp == 1);
return status;
}
......@@ -112,9 +113,9 @@ int main(int argc, char **argv)
{
int status;
assert(testfunc(SUC) == 0);
internal_assert(testfunc(SUC) == 0);
assert(testfunc(NORMAL) == 0);
internal_assert(testfunc(NORMAL) == 0);
status = testfunc(FAIL);
assert(WIFEXITED(status) && WEXITSTATUS(status) == 1);
......
......@@ -22,7 +22,6 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
......@@ -32,13 +31,7 @@
#include "igt_core.h"
/*
* We need to hide assert from the cocci igt test refactor spatch.
*
* IMPORTANT: Test infrastructure tests are the only valid places where using
* assert is allowed.
*/
#define internal_assert assert
#include "igt_tests_common.h"
char test[] = "test";
char *argv_run[] = { test };
......
......@@ -38,19 +38,12 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include "drmtest.h"
#include "igt_core.h"
/*
* We need to hide assert from the cocci igt test refactor spatch.
*
* IMPORTANT: Test infrastructure tests are the only valid places where using
* assert is allowed.
*/
#define internal_assert assert
#include "igt_tests_common.h"
bool simple;
bool runa;
......
......@@ -28,19 +28,12 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include "drmtest.h"
#include "igt_core.h"
/*
* We need to hide assert from the cocci igt test refactor spatch.
*
* IMPORTANT: Test infrastructure tests are the only valid places where using
* assert is allowed.
*/
#define internal_assert assert
#include "igt_tests_common.h"
bool simple;
bool list_subtests;
......
......@@ -22,9 +22,10 @@
*
*/
#include <assert.h>
#include "igt_core.h"
#include "igt_tests_common.h"
igt_main
{
bool t1 = false;
......@@ -41,7 +42,7 @@ igt_main
}
igt_subtest("not-run") {
assert(0);
internal_assert(0);
}
igt_subtest_group {
......@@ -49,35 +50,35 @@ igt_main
* restore to "run testcases" when an outer
* group is already in SKIP state. */
igt_subtest("still-not-run") {
assert(0);
internal_assert(0);
}
}
}
igt_subtest("run") {
t1 = true;
assert(1);
internal_assert(1);
}
}
igt_subtest_group {
igt_fixture {
assert(t2 == 0);
internal_assert(t2 == 0);
t2 = 1;
}
igt_subtest("run-again") {
assert(t2 == 1);
internal_assert(t2 == 1);
t2 = 2;
}
igt_fixture {
assert(t2 == 2);
internal_assert(t2 == 2);
t2 = 3;
}
}
assert(t1);
assert(t2 == 3);
internal_assert(t1);
internal_assert(t2 == 3);
}
/*
* Copyright © 2019 Intel Corporation
*
* 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 (including the next
* paragraph) 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.
*
*/
#ifndef IGT_LIB_TESTS_COMMON_H
#define IGT_LIB_TESTS_COMMON_H
#include <assert.h>
/*
* We need to hide assert from the cocci igt test refactor spatch.
*
* IMPORTANT: Test infrastructure tests are the only valid places where using
* assert is allowed.
*/
#define internal_assert assert
#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