Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2021, Oracle and/or its affiliates. */
0003 
0004 #include <test_progs.h>
0005 
0006 /* Test that verifies exception handling is working. fork()
0007  * triggers task_newtask tracepoint; that new task will have a
0008  * NULL pointer task_works, and the associated task->task_works->func
0009  * should not be NULL if task_works itself is non-NULL.
0010  *
0011  * So to verify exception handling we want to see a NULL task_works
0012  * and task_works->func; if we see this we can conclude that the
0013  * exception handler ran when we attempted to dereference task->task_works
0014  * and zeroed the destination register.
0015  */
0016 #include "exhandler_kern.skel.h"
0017 
0018 void test_exhandler(void)
0019 {
0020     int err = 0, duration = 0, status;
0021     struct exhandler_kern *skel;
0022     pid_t cpid;
0023 
0024     skel = exhandler_kern__open_and_load();
0025     if (CHECK(!skel, "skel_load", "skeleton failed: %d\n", err))
0026         goto cleanup;
0027 
0028     skel->bss->test_pid = getpid();
0029 
0030     err = exhandler_kern__attach(skel);
0031     if (!ASSERT_OK(err, "attach"))
0032         goto cleanup;
0033     cpid = fork();
0034     if (!ASSERT_GT(cpid, -1, "fork failed"))
0035         goto cleanup;
0036     if (cpid == 0)
0037         _exit(0);
0038     waitpid(cpid, &status, 0);
0039 
0040     ASSERT_NEQ(skel->bss->exception_triggered, 0, "verify exceptions occurred");
0041 cleanup:
0042     exhandler_kern__destroy(skel);
0043 }