Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhauled tests for pointers containing numeric types #293

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions libtest/PointerNumericTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <sys/types.h>
#include <sys/param.h>

#ifndef __mips__
# include <stdint.h>
#endif

#if defined(__mips64) || defined(__PASE__)
# include <stdint.h>
#endif

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

// Let's define the stdint.h typedefs ourselves if they can't be found
#if !defined(_STDINT_H_) && !defined(_STDINT_H) && !defined(_SYS__STDINT_H_) && !defined(_H_STDINT)
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef signed long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#endif

typedef long double ldouble;
typedef unsigned long ulong;
typedef void* pointer;
typedef void* ptr;
typedef enum Enum_t {e0, e1, e2, e3} Enum;
typedef bool boolean;

#define RET(T) T ptr_num_ret_##T(void *p, int offset) { \
T tmp; memcpy(&tmp, (ptr) (p + offset), sizeof(tmp)); return tmp; \
}
#define SET(T) void ptr_num_set_##T(void *p, int offset, T value) { \
memcpy((ptr) (p + offset), &value, sizeof(value)); \
}

#define TEST(T) SET(T) RET(T)

TEST(int8_t);
TEST(int16_t);
TEST(int32_t);
TEST(long);
TEST(int64_t);

TEST(uint8_t);
TEST(uint16_t);
TEST(uint32_t);
TEST(ulong);
TEST(uint64_t);

TEST(float);
TEST(double);
TEST(ldouble);

TEST(boolean);
TEST(pointer);
TEST(Enum);

void *ptr_num_arr_get(void **array, int index) {
return array[index];
}

void ptr_num_arr_set(void **array, int index, void *value) {
array[index] = value;
}
41 changes: 0 additions & 41 deletions libtest/PointerTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,3 @@ ptr_free(void* ptr)
{
free(ptr);
}

#define swap(p1, p2) do { typeof(*p1) tmp__ = *p1; *p1 = *p2; *p2 = tmp__; } while (0)
void
ptr_reverse_l6(long* l1, long* l2, long* l3, long* l4, long* l5, long* l6)
{
swap(l1, l6);
swap(l2, l5);
swap(l3, l4);
}

void
ptr_reverse_l5(long* l1, long* l2, long* l3, long* l4, long* l5)
{
swap(l1, l5);
(void)(l3);
swap(l2, l4);
}


void
ptr_rotate_l5(long* l1, long* l2, long* l3, long* l4, long* l5)
{
long tmp = *l1;
swap(l5, l1);
swap(l4, l5);
swap(l3, l4);
swap(l2, l3);
*l2 = tmp;
}

void
ptr_rotate_l6(long* l1, long* l2, long* l3, long* l4, long* l5, long* l6)
{
long t = *l1;
swap(l6, l1);
swap(l5, l6);
swap(l4, l5);
swap(l3, l4);
swap(l2, l3);
*l2 = t;
}
Loading