infix
A JIT-Powered FFI Library for C
|
Tests FFI functionality with all supported primitive C types. More...
#include "common/double_tap.h"
#include "common/infix_config.h"
#include <infix/infix.h>
#include <inttypes.h>
Macros | |
#define | DBLTAP_IMPLEMENTATION |
#define | TEST_PRIMITIVE(test_name, c_type, infix_id, passthrough_func, input_val, format_specifier) |
A helper macro to generate a subtest for a specific primitive type. | |
Functions | |
bool | passthrough_bool (bool v) |
uint8_t | passthrough_uint8 (uint8_t v) |
int8_t | passthrough_sint8 (int8_t v) |
uint16_t | passthrough_uint16 (uint16_t v) |
int16_t | passthrough_sint16 (int16_t v) |
uint32_t | passthrough_uint32 (uint32_t v) |
int32_t | passthrough_sint32 (int32_t v) |
uint64_t | passthrough_uint64 (uint64_t v) |
int64_t | passthrough_sint64 (int64_t v) |
float | passthrough_float (float v) |
double | passthrough_double (double v) |
long double | passthrough_long_double (long double v) |
__uint128_t | passthrough_uint128 (__uint128_t v) |
__int128_t | passthrough_sint128 (__int128_t v) |
TEST_PRIMITIVE ("bool", bool, INFIX_PRIMITIVE_BOOL, passthrough_bool, true, "%d") | |
TEST_PRIMITIVE ("uint8_t", uint8_t, INFIX_PRIMITIVE_UINT8, passthrough_uint8, 255, "%u") | |
TEST_PRIMITIVE ("int8_t", int8_t, INFIX_PRIMITIVE_SINT8, passthrough_sint8, -128, "%d") | |
TEST_PRIMITIVE ("uint16_t", uint16_t, INFIX_PRIMITIVE_UINT16, passthrough_uint16, 65535, "%u") | |
TEST_PRIMITIVE ("int16_t", int16_t, INFIX_PRIMITIVE_SINT16, passthrough_sint16, -32768, "%d") | |
TEST_PRIMITIVE ("uint32_t", uint32_t, INFIX_PRIMITIVE_UINT32, passthrough_uint32, 0xFFFFFFFF, "%u") | |
TEST_PRIMITIVE ("int32_t", int32_t, INFIX_PRIMITIVE_SINT32, passthrough_sint32, -2147483647 - 1, "%d") | |
TEST_PRIMITIVE ("uint64_t", uint64_t, INFIX_PRIMITIVE_UINT64, passthrough_uint64, 0xFFFFFFFFFFFFFFFF, "%" PRIu64) | |
TEST_PRIMITIVE ("int64_t", int64_t, INFIX_PRIMITIVE_SINT64, passthrough_sint64, -9223372036854775807LL - 1, "%" PRId64) | |
TEST_PRIMITIVE ("float", float, INFIX_PRIMITIVE_FLOAT, passthrough_float, 3.14159f, "%f") | |
TEST_PRIMITIVE ("double", double, INFIX_PRIMITIVE_DOUBLE, passthrough_double, 2.718281828459045, "%f") | |
subtest ("long double") | |
subtest ("__uint128_t") | |
subtest ("__int128_t") | |
Variables | |
TEST | |
Tests FFI functionality with all supported primitive C types.
Copyright (c) 2025 Sanko Robinson
This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.
SPDX-License-Identifier: (Artistic-2.0 OR MIT)
The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
SPDX-License-Identifier: CC-BY-4.0
This test suite verifies the core capability of the infix library to handle all fundamental C data types. It does this by creating a simple "passthrough" C function for each primitive (e.g., bool
, int8_t
, double
, __int128_t
).
For each type, the test performs the following steps:
infix_type
using infix_type_create_primitive
.This process validates that the library correctly handles the size, alignment, and ABI-specific calling conventions for every primitive type on the target platform, forming the foundational layer of the entire test suite.
These tests use the manual API to test primitive types to verify functionality without bringing the signature system in.
#define DBLTAP_IMPLEMENTATION |
#define TEST_PRIMITIVE | ( | test_name, | |
c_type, | |||
infix_id, | |||
passthrough_func, | |||
input_val, | |||
format_specifier | |||
) |
A helper macro to generate a subtest for a specific primitive type.
This macro encapsulates the repetitive logic for testing a single primitive type. It creates a subtest, generates a trampoline, performs the FFI call, checks the result, and cleans up resources. This reduces code duplication and makes the test suite easier to read and maintain.
test_name | The string name for the subtest. |
c_type | The C data type (e.g., uint8_t ). |
infix_id | The infix_primitive_type_id enum value. |
passthrough_func | The name of the native C passthrough function. |
input_val | A literal value to use for testing. |
format_specifier | A printf format specifier for diagnostic messages. |
bool passthrough_bool | ( | bool | v | ) |
double passthrough_double | ( | double | v | ) |
float passthrough_float | ( | float | v | ) |
long double passthrough_long_double | ( | long double | v | ) |
__int128_t passthrough_sint128 | ( | __int128_t | v | ) |
int16_t passthrough_sint16 | ( | int16_t | v | ) |
int32_t passthrough_sint32 | ( | int32_t | v | ) |
int64_t passthrough_sint64 | ( | int64_t | v | ) |
int8_t passthrough_sint8 | ( | int8_t | v | ) |
__uint128_t passthrough_uint128 | ( | __uint128_t | v | ) |
uint16_t passthrough_uint16 | ( | uint16_t | v | ) |
uint32_t passthrough_uint32 | ( | uint32_t | v | ) |
uint64_t passthrough_uint64 | ( | uint64_t | v | ) |
uint8_t passthrough_uint8 | ( | uint8_t | v | ) |
subtest | ( | "__int128_t" | ) |
subtest | ( | "__uint128_t" | ) |
subtest | ( | "long double" | ) |
TEST_PRIMITIVE | ( | "bool" | , |
bool | , | ||
INFIX_PRIMITIVE_BOOL | , | ||
passthrough_bool | , | ||
true | , | ||
"%d" | |||
) |
TEST_PRIMITIVE | ( | "double" | , |
double | , | ||
INFIX_PRIMITIVE_DOUBLE | , | ||
passthrough_double | , | ||
2. | 718281828459045, | ||
"%f" | |||
) |
TEST_PRIMITIVE | ( | "float" | , |
float | , | ||
INFIX_PRIMITIVE_FLOAT | , | ||
passthrough_float | , | ||
3. | 14159f, | ||
"%f" | |||
) |
TEST_PRIMITIVE | ( | "int16_t" | , |
int16_t | , | ||
INFIX_PRIMITIVE_SINT16 | , | ||
passthrough_sint16 | , | ||
- | 32768, | ||
"%d" | |||
) |
TEST_PRIMITIVE | ( | "int32_t" | , |
int32_t | , | ||
INFIX_PRIMITIVE_SINT32 | , | ||
passthrough_sint32 | , | ||
-2147483647 - | 1, | ||
"%d" | |||
) |
TEST_PRIMITIVE | ( | "int64_t" | , |
int64_t | , | ||
INFIX_PRIMITIVE_SINT64 | , | ||
passthrough_sint64 | , | ||
-9223372036854775807LL - | 1, | ||
"%" | PRId64 | ||
) |
TEST_PRIMITIVE | ( | "int8_t" | , |
int8_t | , | ||
INFIX_PRIMITIVE_SINT8 | , | ||
passthrough_sint8 | , | ||
- | 128, | ||
"%d" | |||
) |
TEST_PRIMITIVE | ( | "uint16_t" | , |
uint16_t | , | ||
INFIX_PRIMITIVE_UINT16 | , | ||
passthrough_uint16 | , | ||
65535 | , | ||
"%u" | |||
) |
TEST_PRIMITIVE | ( | "uint32_t" | , |
uint32_t | , | ||
INFIX_PRIMITIVE_UINT32 | , | ||
passthrough_uint32 | , | ||
0xFFFFFFFF | , | ||
"%u" | |||
) |
TEST_PRIMITIVE | ( | "uint64_t" | , |
uint64_t | , | ||
INFIX_PRIMITIVE_UINT64 | , | ||
passthrough_uint64 | , | ||
0xFFFFFFFFFFFFFFFF | , | ||
"%" | PRIu64 | ||
) |
TEST_PRIMITIVE | ( | "uint8_t" | , |
uint8_t | , | ||
INFIX_PRIMITIVE_UINT8 | , | ||
passthrough_uint8 | , | ||
255 | , | ||
"%u" | |||
) |