embeddedartistry / libc

libc targeted for embedded systems usage. Reduced set of functionality (due to embedded nature). Chosen for portability and quick bringup.
MIT License
520 stars 67 forks source link

Add proper tests for div, ldiv, imaxdiv #10

Closed phillipjohnston closed 2 years ago

phillipjohnston commented 7 years ago

There are four division functions:

Currently, we only have tests that cover lldiv (test/stdlib/lldiv.c). The tests for div are simply a copy of lldiv, and not really testing div(). ldiv and imax div are untested altogether.

To test the other functions, we essentially need to copy the method used to test lldiv.c, but adjust the types and table definitions.

The values in lldiv can be repurposed to test out imaxdiv, but the suffix of "ull" will need to be changed to "ll" in that file. But new tables of values will need to be generated for div and ldiv.

For div and ldiv, you will need to create a new table that has numbers x, y, and the corresponding div and mod values. Make sure to pick a range of big and small values. The table does not have to be as comprehensive as what exists for lldiv.

phillipjohnston commented 2 years ago

Example I showed for the int tests:

static struct
{
    int x, y, div, mod;
} t[] = {
    {1, 1, 1, 0},
    {2, 1, 2, 0},
    {1, 2, 0, 1}
         };

And the test would then be adjusted to use int as the type.

static void div_test(void** __attribute__((unused)) state)
{
    int x, y, div, mod;
    size_t i;

     // .. more here
}
AdhamEA commented 2 years ago

Clair Sir