CS318 - Pintos
Pintos source browser for JHU CS318 course
Macros | Functions
stdlib.c File Reference
#include <debug.h>
#include <limits.h>
#include <random.h>
#include <stdlib.h>
#include <stdio.h>
#include "threads/test.h"
Include dependency graph for stdlib.c:

Go to the source code of this file.

Macros

#define MAX_CNT   4096
 Test program for sorting and searching in lib/stdlib.c. More...
 

Functions

static void shuffle (int[], size_t)
 
static int compare_ints (const void *a_, const void *b_)
 Returns 1 if *A is greater than *B, 0 if *A equals *B, -1 if *A is less than *B. More...
 
static void verify_order (const int[], size_t)
 
static void verify_bsearch (const int[], size_t)
 
void test (void)
 Test sorting and searching implementations. More...
 
static void shuffle (int *array, size_t cnt)
 Shuffles the CNT elements in ARRAY into random order. More...
 
static void verify_order (const int *array, size_t cnt)
 Verifies that ARRAY contains the CNT ints 0...CNT-1. More...
 
static void verify_bsearch (const int *array, size_t cnt)
 Checks that bsearch() works properly in ARRAY. More...
 

Macro Definition Documentation

◆ MAX_CNT

#define MAX_CNT   4096

Test program for sorting and searching in lib/stdlib.c.

Attempts to test the sorting and searching functionality that is not sufficiently tested elsewhere in Pintos.

This is not a test we will run on your submitted projects. It is here for completeness. Maximum number of elements in an array that we will test.

Definition at line 19 of file stdlib.c.

Function Documentation

◆ compare_ints()

static int compare_ints ( const void *  a_,
const void *  b_ 
)
static

Returns 1 if *A is greater than *B, 0 if *A equals *B, -1 if *A is less than *B.

Definition at line 78 of file stdlib.c.

Referenced by test(), and verify_bsearch().

Here is the caller graph for this function:

◆ shuffle() [1/2]

static void shuffle ( int *  array,
size_t  cnt 
)
static

Shuffles the CNT elements in ARRAY into random order.

Definition at line 61 of file stdlib.c.

References random_ulong().

Here is the call graph for this function:

◆ shuffle() [2/2]

static void shuffle ( int  [],
size_t   
)
static

Referenced by test().

Here is the caller graph for this function:

◆ test()

void test ( void  )

Test sorting and searching implementations.

Definition at line 28 of file stdlib.c.

References compare_ints(), MAX_CNT, printf(), qsort(), shuffle(), verify_bsearch(), and verify_order().

Here is the call graph for this function:

◆ verify_bsearch() [1/2]

static void verify_bsearch ( const int *  array,
size_t  cnt 
)
static

Checks that bsearch() works properly in ARRAY.

ARRAY must contain the values 0...CNT-1.

Definition at line 99 of file stdlib.c.

References ASSERT, bsearch(), compare_ints(), INT_MAX, MAX_CNT, and NULL.

Here is the call graph for this function:

◆ verify_bsearch() [2/2]

static void verify_bsearch ( const int  [],
size_t   
)
static

Referenced by test().

Here is the caller graph for this function:

◆ verify_order() [1/2]

static void verify_order ( const int *  array,
size_t  cnt 
)
static

Verifies that ARRAY contains the CNT ints 0...CNT-1.

Definition at line 88 of file stdlib.c.

References ASSERT.

◆ verify_order() [2/2]

static void verify_order ( const int  [],
size_t   
)
static

Referenced by test().

Here is the caller graph for this function: