import RT-Thread@9217865c without bsp, libcpu and components/net

This commit is contained in:
Zihao Yu 2023-05-20 16:23:33 +08:00
commit e2376a3709
1414 changed files with 390370 additions and 0 deletions

View file

@ -0,0 +1,23 @@
menuconfig RTT_POSIX_TESTCASE_STDLIB_H
bool "<stdlib.h>"
default n
if RTT_POSIX_TESTCASE_STDLIB_H
config STDLIB_H_ATOI
bool "<stdlib.h> -> atoi"
default n
config STDLIB_H_ATOL
bool "<stdlib.h> -> atol"
default n
config STDLIB_H_QSORT
bool "<stdlib.h> -> qsort"
default n
config STDLIB_H_STRTOL
bool "<stdlib.h> -> strtol"
default n
endif

View file

@ -0,0 +1,27 @@
import rtconfig
Import('RTT_ROOT')
from building import *
# get current directory
cwd = GetCurrentDir()
path = [cwd]
src = []
if GetDepend('RTT_POSIX_TESTCASE_STDLIB_H'):
src += Glob('./definitions/*.c')
if GetDepend('STDLIB_H_ATOI'):
src += Glob('./functions/atoi_tc.c')
if GetDepend('STDLIB_H_ATOL'):
src += Glob('./functions/atol_tc.c')
if GetDepend('STDLIB_H_QSORT'):
src += Glob('./functions/qsort_tc.c')
if GetDepend('STDLIB_H_STRTOL'):
src += Glob('./functions/strtol_tc.c')
group = DefineGroup('rtt_posix_testcase', src, depend = ['RTT_POSIX_TESTCASE_STDLIB_H'], CPPPATH = path)
Return('group')

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2004, Bull SA. All rights reserved.
* Created by: Laurent.Vivier@bull.net
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*/
/* test if stdlib.h exists and can be included */
// #define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <sys/time.h>
#ifndef __compar_fn_t_defined
#define __compar_fn_t_defined
typedef int (*__compar_fn_t) (const void *, const void *);
#endif
void (*test_abort)(void);
int (*test_abs)(int);
double (*test_atof)(const char *__nptr);
int (*test_atoi)(const char *__nptr);
long (*test_atol)(const char *__nptr);
long long (*test_atoll)(const char *__nptr);
void * (*test_bsearch)(const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t _compar);
void * (*test_calloc)(size_t, size_t);
div_t (*test_div)(int __numer, int __denom);
void (*test_free)(void *);
char * (*test_getenv)(const char *__string);
long (*test_labs)(long);
ldiv_t (*test_ldiv)(long __numer, long __denom);
void * (*test_malloc)(size_t);
void (*test_qsort)(void *__base, size_t __nmemb, size_t __size, __compar_fn_t _compar);
int (*test_rand)(void);
int (*test_rand_r)(unsigned *__seed);
void * (*test_realloc)(void *, size_t);
int (*test_setenv)(const char *__string, const char *__value, int __overwrite);
void (*test_srand)(unsigned __seed);
double (*test_strtod)(const char *__restrict __n, char **__restrict __end_PTR);
float (*test_strtof)(const char *__restrict __n, char **__restrict __end_PTR);
long (*test_strtol)(const char *__restrict __n, char **__restrict __end_PTR, int __base);
long double (*test_strtold)(const char *__restrict, char **__restrict);
long long (*test_strtoll)(const char *__restrict __n, char **__restrict __end_PTR, int __base);
unsigned long (*test_strtoul)(const char *__restrict __n, char **__restrict __end_PTR, int __base);
unsigned long long (*test_strtoull)(const char *__restrict __n, char **__restrict __end_PTR, int __base);
int (*test_unsetenv)(const char *__string);
__attribute__((unused)) static int test_defined()
{
test_abort = abort;
test_abs = abs;
test_atof = atof;
test_atoi = atoi;
test_atol = atol;
test_atoll = atoll;
test_bsearch = bsearch;
test_calloc = calloc;
test_div = div;
test_free = free;
test_getenv = getenv;
test_labs = labs;
test_ldiv = ldiv;
test_malloc = malloc;
test_qsort = qsort;
test_rand = rand;
// test_rand_r = rand_r;
test_realloc = realloc;
// test_setenv = setenv;
test_srand = srand;
test_strtod = strtod;
test_strtof = strtof;
test_strtol = strtol;
test_strtold = strtold;
test_strtoll = strtoll;
test_strtoul = strtoul;
test_strtoull = strtoull;
// test_unsetenv = unsetenv;
return 0;
}

View file

@ -0,0 +1,67 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct atoi_data
{
char string[15]; // int max 2147483647
int ret_num;
};
struct atoi_data test_data[] =
{
/* positive integer */
{"0", 0},
{"1", 1},
{"1.123", 1},
{"123", 123},
{"98993489", 98993489},
{"98993489.12", 98993489},
{"2147483647", 2147483647},
/* negtive integer */
{"-1", -1},
{"-1.123", -1},
{"-123", -123},
{"-98993489", -98993489},
{"-98993489.12", -98993489},
{"-2147483647", -2147483647},
/* letters and numbers */
{"12a45", 12},
{"-12a45", -12},
{"12/45", 12},
{"-12/45", -12},
/* cannot be resolved */
{"", 0},
{" ", 0},
{"abc12", 0},
{" abc12", 0},
/* {NULL, -1} compiler warning */
};
#include <utest.h>
int atoi_entry(void)
{
int i = 0;
int res = 0;
for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++)
{
res = atoi(test_data[i].string);
uassert_int_equal(res, test_data[i].ret_num);
}
return 0;
}
static void test_atoi(void)
{
atoi_entry();
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_atoi);
}
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.atoi_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,69 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct atol_data
{
char string[15]; // long max 2147483647
int ret_num;
};
struct atol_data test_data1[] =
{
/* positive integer */
{"0", 0},
{"1", 1},
{"1.123", 1},
{"123", 123},
{"98993489", 98993489},
{"98993489.12", 98993489},
{"2147483647", 2147483647},
/* negtive integer */
{"-1", -1},
{"-1.123", -1},
{"-123", -123},
{"-98993489", -98993489},
{"-98993489.12", -98993489},
{"-2147483647", -2147483647},
/* letters and numbers */
{"12a45", 12},
{"-12a45", -12},
{"12/45", 12},
{"-12/45", -12},
/* cannot be resolved */
{"", 0},
{" ", 0},
{"abc12", 0},
{" abc12", 0},
/* {NULL, -1} compiler warning */
};
#include <utest.h>
int atol_entry(void)
{
int i = 0;
int res = 0;
for (i = 0; i < sizeof(test_data1) / sizeof(test_data1[0]); i++)
{
res = atol(test_data1[i].string);
uassert_int_equal(res, test_data1[i].ret_num);
}
return 0;
}
static void test_atol(void)
{
atol_entry();
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_atol);
}
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.atol_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,136 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <utest.h>
static int scmp(const void *a, const void *b)
{
return strcmp(*(char **)a, *(char **)b);
}
static int icmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
static int ccmp(const void *a, const void *b)
{
return *(char *)a - *(char *)b;
}
/**
* static int cmp64(const void *a, const void *b)
* {
* const uint64_t *ua = a, *ub = b;
* return *ua < *ub ? -1 : *ua != *ub;
* }
*/
/* 26 items -- even */
static const char *s[] =
{
"Bob", "Alice", "John", "Ceres",
"Helga", "Drepper", "Emeralda", "Zoran",
"Momo", "Frank", "Pema", "Xavier",
"Yeva", "Gedun", "Irina", "Nono",
"Wiener", "Vincent", "Tsering", "Karnica",
"Lulu", "Quincy", "Osama", "Riley",
"Ursula", "Sam"
};
static const char *s_sorted[] =
{
"Alice", "Bob", "Ceres", "Drepper",
"Emeralda", "Frank", "Gedun", "Helga",
"Irina", "John", "Karnica", "Lulu",
"Momo", "Nono", "Osama", "Pema",
"Quincy", "Riley", "Sam", "Tsering",
"Ursula", "Vincent", "Wiener", "Xavier",
"Yeva", "Zoran"
};
/* 23 items -- odd, prime */
static int n[] =
{
879045, 394, 99405644, 33434, 232323, 4334, 5454,
343, 45545, 454, 324, 22, 34344, 233, 45345, 343,
848405, 3434, 3434344, 3535, 93994, 2230404, 4334
};
static int n_sorted[] =
{
22, 233, 324, 343, 343, 394, 454, 3434,
3535, 4334, 4334, 5454, 33434, 34344, 45345, 45545,
93994, 232323, 848405, 879045, 2230404, 3434344, 99405644
};
static void str_test(const char **a, const char **a_sorted, int len)
{
int i;
qsort(a, len, sizeof * a, scmp);
for (i = 0; i < len; i++)
{
uassert_true(strcmp(a[i], a_sorted[i]) == 0);
}
}
static void int_test(int *a, int *a_sorted, int len)
{
int i;
qsort(a, len, sizeof * a, icmp);
for (i = 0; i < len; i++)
{
uassert_true(a[i] == a_sorted[i]);
}
}
#define T(a, a_sorted) do { \
char p[] = a; \
qsort(p, sizeof p - 1, 1, ccmp); \
uassert_true(memcmp(p, a_sorted, sizeof p) == 0);\
} while(0)
static void char_test(void)
{
T("", "");
T("1", "1");
T("11", "11");
T("12", "12");
T("21", "12");
T("111", "111");
T("211", "112");
T("121", "112");
T("112", "112");
T("221", "122");
T("212", "122");
T("122", "122");
T("123", "123");
T("132", "123");
T("213", "123");
T("231", "123");
T("321", "123");
T("312", "123");
T("1423", "1234");
T("51342", "12345");
T("261435", "123456");
T("4517263", "1234567");
T("37245618", "12345678");
T("812436597", "123456789");
T("987654321", "123456789");
T("321321321", "111222333");
T("49735862185236174", "11223344556677889");
}
void posix_testcase(void)
{
str_test(s, s_sorted, sizeof s / sizeof * s);
int_test(n, n_sorted, sizeof n / sizeof * n);
char_test();
/* todo uint64 test */
}
static void testcase(void)
{
UTEST_UNIT_RUN(posix_testcase);
}
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.qsort_tc.c", RT_NULL, RT_NULL, 10);

View file

@ -0,0 +1,125 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define TEST(r, f, x, m) uassert_int_equal(f, x)
#define TEST2(r, f, x, m) uassert_int_equal(f, x)
#define TEST3(r, f, x, m) uassert_int_not_equal(f, x)
#include <utest.h>
#define ERANGE 34
#define EINVAL 22
int strtol_entry(void)
{
__attribute__((unused)) int i;
__attribute__((unused)) long l;
__attribute__((unused)) unsigned long ul;
__attribute__((unused)) long long ll;
__attribute__((unused)) unsigned long long ull;
__attribute__((unused)) char *msg = "";
__attribute__((unused)) char *s, *c;
TEST(l, atol("2147483647"), 2147483647L, "max 32bit signed %ld != %ld");
TEST(l, strtol("2147483647", 0, 0), 2147483647L, "max 32bit signed %ld != %ld");
TEST(ul, strtoul("4294967295", 0, 0), 4294967295UL, "max 32bit unsigned %lu != %lu");
if (sizeof(long) == 4)
{
TEST(l, strtol(s = "2147483648", &c, 0), 2147483647L, "uncaught overflow %ld != %ld");
TEST2(i, c - s, 10, "wrong final position %d != %d");
TEST(l, strtol(s = "-2147483649", &c, 0), -2147483647L - 1, "uncaught overflow %ld != %ld");
TEST2(i, c - s, 11, "wrong final position %d != %d");
TEST(ul, strtoul(s = "4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
TEST2(i, c - s, 10, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-1", &c, 0), -1UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 2, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-2", &c, 0), -2UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 2, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-2147483648", &c, 0), -2147483648UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 11, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-2147483649", &c, 0), -2147483649UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 11, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-4294967296", &c, 0), 4294967295UL, "uncaught negative overflow %lu != %lu");
TEST2(i, c - s, 11, "wrong final position %d != %d");
}
else if (sizeof(long) == 8)
{
TEST(l, strtol(s = "9223372036854775808", &c, 0), 9223372036854775807L, "uncaught overflow %ld != %ld");
TEST2(i, c - s, 19, "wrong final position %d != %d");
TEST(l, strtol(s = "-9223372036854775809", &c, 0), -9223372036854775807L - 1, "uncaught overflow %ld != %ld");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ul, strtoul(s = "18446744073709551616", &c, 0), 18446744073709551615UL, "uncaught overflow %lu != %lu");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-1", &c, 0), -1UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 2, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-2", &c, 0), -2UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 2, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-9223372036854775808", &c, 0), -9223372036854775808UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-9223372036854775809", &c, 0), -9223372036854775809UL, "rejected negative %lu != %lu");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ul, strtoul(s = "-18446744073709551616", &c, 0), 18446744073709551615UL, "uncaught negative overflow %lu != %lu");
TEST2(i, c - s, 21, "wrong final position %d != %d");
}
else
{
printf("sizeof(long) == %d, not implemented\n", (int)sizeof(long));
}
if (sizeof(long long) == 8)
{
TEST(ll, strtoll(s = "9223372036854775808", &c, 0), 9223372036854775807LL, "uncaught overflow %lld != %lld");
TEST2(i, c - s, 19, "wrong final position %d != %d");
TEST(ll, strtoll(s = "-9223372036854775809", &c, 0), -9223372036854775807LL - 1, "uncaught overflow %lld != %lld");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ull, strtoull(s = "18446744073709551616", &c, 0), 18446744073709551615ULL, "uncaught overflow %llu != %llu");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ull, strtoull(s = "-1", &c, 0), -1ULL, "rejected negative %llu != %llu");
TEST2(i, c - s, 2, "wrong final position %d != %d");
TEST(ull, strtoull(s = "-2", &c, 0), -2ULL, "rejected negative %llu != %llu");
TEST2(i, c - s, 2, "wrong final position %d != %d");
TEST(ull, strtoull(s = "-9223372036854775808", &c, 0), -9223372036854775808ULL, "rejected negative %llu != %llu");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ull, strtoull(s = "-9223372036854775809", &c, 0), -9223372036854775809ULL, "rejected negative %llu != %llu");
TEST2(i, c - s, 20, "wrong final position %d != %d");
TEST(ull, strtoull(s = "-18446744073709551616", &c, 0), 18446744073709551615ULL, "uncaught negative overflow %llu != %llu");
TEST2(i, c - s, 21, "wrong final position %d != %d");
}
else
{
printf("sizeof(long long) == %d, not implemented\n", (int)sizeof(long long));
}
TEST(l, strtol("z", 0, 36), 35L, "%ld != %ld");
TEST(l, strtol("00010010001101000101011001111000", 0, 2), 0x12345678L, "%ld != %ld");
TEST(l, strtol(s = "0F5F", &c, 16), 0x0f5fL, "%ld != %ld");
TEST(l, strtol(s = "0xz", &c, 16), 0L, "%ld != %ld");
TEST3(i, c - s, 1, "wrong final position %ld != %ld");
TEST(l, strtol(s = "0x1234", &c, 16), 0x1234, "%ld != %ld");
TEST2(i, c - s, 6, "wrong final position %ld != %ld");
c = NULL;
TEST3(l, strtol(s = "123", &c, 37), 0, "%ld != %ld");
TEST3(i, c - s, 0, "wrong final position %d != %d");
TEST(l, strtol(s = " 15437", &c, 8), 015437, "%ld != %ld");
TEST2(i, c - s, 7, "wrong final position %d != %d");
TEST(l, strtol(s = " 1", &c, 0), 1, "%ld != %ld");
TEST2(i, c - s, 3, "wrong final position %d != %d");
return 0;
}
static void test_strtol(void)
{
strtol_entry();
}
static void testcase(void)
{
UTEST_UNIT_RUN(test_strtol);
}
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.strtol_tc.c", RT_NULL, RT_NULL, 10);