Compare commits
4 Commits
main
...
763781b92d
Author | SHA1 | Date | |
---|---|---|---|
763781b92d
|
|||
86894713ac
|
|||
97ab23ecdf
|
|||
dbd7f58025
|
@@ -1,6 +1,3 @@
|
||||
#ifndef INCLUDE_SET_LIST_
|
||||
#define INCLUDE_SET_LIST_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct SETBlockMeta
|
||||
@@ -34,5 +31,3 @@ void set_ll_free_all(struct SETBlockMeta *head);
|
||||
*/
|
||||
|
||||
struct SETBlockMeta *set_ll_free_one(struct SETBlockMeta *head, void *address);
|
||||
|
||||
#endif
|
||||
|
@@ -1,28 +1,19 @@
|
||||
#ifndef __cplusplus
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdio>
|
||||
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef INCLUDE_SET_H
|
||||
#define INCLUDE_SET_H
|
||||
|
||||
#define SET_MAX_ERROR_MSG_SIZE 256
|
||||
#define SET_MAX_NAME_SIZE 64
|
||||
|
||||
/**
|
||||
* Meta data for one test function.
|
||||
*
|
||||
@@ -53,8 +44,8 @@ extern "C"
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal function header for bundle. Use BUNDLE() macro to define bundle
|
||||
* in test.
|
||||
* Internal function header for bundle. Use BUNDLE() macro to define bundle in
|
||||
* test.
|
||||
*/
|
||||
void set_bundle_suits(struct SETSuit **suits, int *counter, bool count);
|
||||
|
||||
@@ -169,8 +160,8 @@ extern "C"
|
||||
void suit_name##_suit(struct SETSuit *suit, bool count); \
|
||||
struct SETSuit *suit_name##_suit_contructor() \
|
||||
{ \
|
||||
struct SETSuit *suit = (struct SETSuit *)mmap( \
|
||||
NULL, sizeof(struct SETSuit), PROT_READ | PROT_WRITE, \
|
||||
struct SETSuit *suit = \
|
||||
mmap(NULL, sizeof(struct SETSuit), PROT_READ | PROT_WRITE, \
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
|
||||
madvise(suit, sizeof(struct SETSuit), MADV_DONTFORK); \
|
||||
suit->len = 0; \
|
||||
@@ -178,8 +169,8 @@ extern "C"
|
||||
suit->shm_key = \
|
||||
create_shared_suit_space(suit->len * sizeof(struct SETest)); \
|
||||
suit->name = #suit_name; \
|
||||
suit->tests = (struct SETest *)shmat(suit->shm_key, 0, 0); \
|
||||
if ((uint64_t)suit->tests == -1) \
|
||||
suit->tests = shmat(suit->shm_key, 0, 0); \
|
||||
if (suit->tests == (struct SETest *)-1) \
|
||||
{ \
|
||||
fprintf(stderr, "Couldn't attach suit space.\n"); \
|
||||
perror("shmat"); \
|
||||
@@ -251,7 +242,3 @@ extern "C"
|
||||
void test_name##_test(struct SETest *test)
|
||||
|
||||
#endif // !INCLUDE_SET_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -3,8 +3,8 @@
|
||||
|
||||
#include "set.h"
|
||||
|
||||
#ifndef INCLUDE_SET_ASSERT_H
|
||||
#define INCLUDE_SET_ASSERT_H
|
||||
#ifndef ASSERT_H
|
||||
#define ASSERT_H
|
||||
|
||||
#define STATIC_ASSERT(condition) (void)sizeof(char[1 - 2 * (!(condition))])
|
||||
|
||||
@@ -21,25 +21,16 @@
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = \
|
||||
format_string("Expect %d not to be %d.\n", act, exp) return; \
|
||||
format_string("Expect %d to be %d.\n", act, exp) return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_MSG(exp, act, msg) \
|
||||
if (exp != act) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected %d to be %d\n Failed with message: " msg, act, exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_MSG(exp, act, msg) \
|
||||
if (exp == act) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected %d not to be %d\n Failed with message: " msg, act, \
|
||||
exp); \
|
||||
test->error_msg = \
|
||||
format_string("Expected %d to be %d\n Failed with message: %s", \
|
||||
act, exp, msg); \
|
||||
return; \
|
||||
}
|
||||
|
||||
@@ -51,15 +42,6 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_TRUE_MSG(x, msg) \
|
||||
if (!x) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected true got false.\n Failed with message: " msg); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_FALSE(x) \
|
||||
if (x) \
|
||||
{ \
|
||||
@@ -68,15 +50,6 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_FALSE_MSG(x, msg) \
|
||||
if (x) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected false got true.\n Failed with message: " msg); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_FLOAT(exp, act, epsilon) \
|
||||
if (fabs(exp - act) <= epsilon) \
|
||||
{ \
|
||||
@@ -86,32 +59,12 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_FLOAT_MSG(exp, act, epsilon, msg) \
|
||||
if (fabs(exp - act) <= epsilon) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected %f to be %f (e: %f)\n Failed with message: " msg, \
|
||||
act, exp, epsilon); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_FLOAT(exp, act, epsilon) \
|
||||
if (fabs(exp - act) > epsilon) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string("Expected %f not to be %f (e: %f)", \
|
||||
act, exp, epsilon); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_FLOAT_MSG(exp, act, epsilon, msg) \
|
||||
if (fabs(exp - act) > epsilon) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected %f not to be %f (e: %f)\n Failed with message: " msg, \
|
||||
act, exp, epsilon); \
|
||||
test->error_msg = \
|
||||
format_string("Expected %f to be %f (e: %f)", act, exp, epsilon); \
|
||||
return; \
|
||||
}
|
||||
|
||||
@@ -124,32 +77,12 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_STR_MSG(exp, act, msg) \
|
||||
if (strcmp(exp, act) != 0) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
type->error_msg = format_string( \
|
||||
"Expected: %d\nBut got: %d\n Failed with message: " msg, act, \
|
||||
exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_STR(exp, act) \
|
||||
if (strcmp(exp, act) == 0) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
type->error_msg = \
|
||||
format_string("Expected not: %d\nBut got: %d", act, exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_STR_MSG(exp, act, msg) \
|
||||
if (strcmp(exp, act) == 0) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
type->error_msg = format_string( \
|
||||
"Expected not: %d\nBut got: %d\n Failed with message: " msg, \
|
||||
act, exp); \
|
||||
format_string("Expected: %d\nBut got: %d", act, exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,5 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef INCLUDE_SET_UTILS_H_
|
||||
#define INCLUDE_SET_UTILS_H_
|
||||
|
||||
/*
|
||||
* Returns pointer to formatted the string.
|
||||
*
|
||||
@@ -55,5 +52,3 @@ void *set_calloc(size_t n, size_t size);
|
||||
* See also: set_malloc()
|
||||
*/
|
||||
void *set_realloc(size_t n);
|
||||
|
||||
#endif
|
||||
|
11
src/list.c
11
src/list.c
@@ -1,6 +1,5 @@
|
||||
#include "list.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void set_ll_append(struct SETBlockMeta *head, struct SETBlockMeta *next)
|
||||
@@ -24,10 +23,9 @@ void set_ll_free_all(struct SETBlockMeta *head)
|
||||
|
||||
struct SETBlockMeta *set_ll_free_one(struct SETBlockMeta *head, void *address)
|
||||
{
|
||||
struct SETBlockMeta *meta =
|
||||
(struct SETBlockMeta *)(address - (sizeof(struct SETBlockMeta)));
|
||||
struct SETBlockMeta *meta = address - (sizeof(struct SETBlockMeta));
|
||||
|
||||
if (meta->prev == NULL)
|
||||
if (meta == head)
|
||||
{
|
||||
struct SETBlockMeta *ret = meta->next;
|
||||
if (ret)
|
||||
@@ -40,11 +38,8 @@ struct SETBlockMeta *set_ll_free_one(struct SETBlockMeta *head, void *address)
|
||||
}
|
||||
|
||||
meta->prev->next = meta->next;
|
||||
|
||||
if (meta->next != NULL)
|
||||
if (meta->next)
|
||||
meta->next->prev = meta->prev;
|
||||
else
|
||||
head->end = meta->prev;
|
||||
|
||||
free(meta);
|
||||
|
||||
|
@@ -48,9 +48,8 @@ int create_shared_suit_space(size_t size)
|
||||
void *set_malloc(size_t n)
|
||||
{
|
||||
void *blocks = malloc(n + sizeof(struct SETBlockMeta));
|
||||
struct SETBlockMeta *meta = (struct SETBlockMeta *)blocks;
|
||||
struct SETBlockMeta *meta = blocks;
|
||||
meta->next = NULL;
|
||||
meta->prev = NULL;
|
||||
|
||||
if (block_meta_head == NULL)
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ TEST(Faculty_Negative)
|
||||
{
|
||||
ASSERT_EQ(fac(-2), 1);
|
||||
ASSERT_EQ(fac(0), 1);
|
||||
ASSERT_TRUE_MSG(false, "Hello");
|
||||
}
|
||||
|
||||
SUIT_SETUP(Basic_Setup)
|
||||
@@ -78,7 +77,6 @@ TEST(Other_With_Malloc)
|
||||
set_free(array);
|
||||
set_free(some_array);
|
||||
|
||||
void *some_other = set_malloc(15);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
|
12
testtest.cpp
12
testtest.cpp
@@ -1,12 +0,0 @@
|
||||
#include "set.h"
|
||||
#include "set_asserts.h"
|
||||
|
||||
NO_SETUP;
|
||||
|
||||
NO_TEAR_DOWN;
|
||||
|
||||
TEST(Basic) { ASSERT_EQ(1, 1); }
|
||||
|
||||
SUIT(Basic) { ADD_TEST(Basic); }
|
||||
|
||||
BUNDLE() { ADD_SUIT(Basic); }
|
Reference in New Issue
Block a user