tests: Add test for sys/ptrtag
This commit is contained in:
parent
ffbb1c1035
commit
65cb8e5074
3
tests/sys_ptrtag/Makefile
Normal file
3
tests/sys_ptrtag/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
include ../Makefile.tests_common
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
61
tests/sys_ptrtag/main.c
Normal file
61
tests/sys_ptrtag/main.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup tests
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Test application for the pointer tagging helpers
|
||||||
|
*
|
||||||
|
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "kernel_defines.h"
|
||||||
|
#include "ptrtag.h"
|
||||||
|
#include "test_utils/expect.h"
|
||||||
|
|
||||||
|
typedef struct PTRTAG {
|
||||||
|
uint8_t a;
|
||||||
|
} custom_type_t;
|
||||||
|
|
||||||
|
/* To rule out that custom type gets aligned by 4 bytes only by chance, we
|
||||||
|
* allocate two subsequently. At least one would be unaligned, if the
|
||||||
|
* alignment requirement is not increased to at least 4
|
||||||
|
*/
|
||||||
|
static custom_type_t a;
|
||||||
|
static custom_type_t b;
|
||||||
|
uint8_t PTRTAG c;
|
||||||
|
uint8_t PTRTAG d;
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
puts(
|
||||||
|
"Test Application for sys/ptrtag\n"
|
||||||
|
"=====================================\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *ptrs[] = {&a, &b, &c, &d};
|
||||||
|
for (uint8_t tag = 0; tag < 4; tag++) {
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(ptrs); i++) {
|
||||||
|
void *ptr = ptrs[i];
|
||||||
|
void *tagged = ptrtag(ptr, tag);
|
||||||
|
expect(ptrtag_ptr(tagged) == ptr);
|
||||||
|
expect(ptrtag_tag(tagged) == tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("TEST PASSED");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
20
tests/sys_ptrtag/tests/01-run.py
Executable file
20
tests/sys_ptrtag/tests/01-run.py
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg
|
||||||
|
#
|
||||||
|
# This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
# General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
# directory for more details.
|
||||||
|
|
||||||
|
# @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from testrunner import run
|
||||||
|
|
||||||
|
|
||||||
|
def testfunc(child):
|
||||||
|
child.expect("TEST PASSED")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(run(testfunc))
|
||||||
Loading…
x
Reference in New Issue
Block a user