Skip to content

Commit e1f4ee3

Browse files
riptlripatel-fd
authored andcommitted
More unit tests
1 parent 1d64948 commit e1f4ee3

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

src/ballet/chacha/test_chacha_rng.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ main( int argc,
1414
FD_TEST( alignof( fd_chacha_rng_t )==fd_chacha_rng_align() );
1515
FD_TEST( sizeof ( _rng )==fd_chacha_rng_footprint() );
1616

17-
fd_chacha_rng_t * rng = fd_chacha_rng_join( fd_chacha_rng_new( _rng, FD_CHACHA_RNG_MODE_MOD ) );
17+
FD_TEST( fd_chacha_rng_new( NULL, FD_CHACHA_RNG_MODE_MOD )==NULL ); /* invalid mem */
18+
FD_TEST( fd_chacha_rng_new( (void *)((ulong)_rng+1UL), FD_CHACHA_RNG_MODE_MOD )==NULL ); /* misaligned mem */
19+
FD_TEST( fd_chacha_rng_new( _rng, 42 )==NULL ); /* invalid mode */
20+
21+
FD_TEST( fd_chacha_rng_new( _rng, FD_CHACHA_RNG_MODE_MOD )==_rng );
22+
FD_TEST( fd_chacha_rng_join( NULL )==NULL ); /* invalid mem */
23+
fd_chacha_rng_t * rng = fd_chacha_rng_join( _rng );
1824
FD_TEST( (ulong)rng == (ulong)_rng );
1925

2026
/* Initialize it with a key */
@@ -94,9 +100,12 @@ main( int argc,
94100
REFILL_TEST( fd_chacha8_rng_refill_seq, 1*FD_CHACHA_BLOCK_SZ );
95101
REFILL_TEST( fd_chacha20_rng_refill_seq, 1*FD_CHACHA_BLOCK_SZ );
96102

97-
/* Clean up */
103+
/* Test leave/delete */
98104

99-
FD_TEST( (ulong)fd_chacha_rng_delete( fd_chacha_rng_leave( rng ) )==(ulong)_rng );
105+
FD_TEST( fd_chacha_rng_leave( NULL )==NULL ); /* invalid mem */
106+
FD_TEST( fd_chacha_rng_leave( rng )==_rng );
107+
FD_TEST( fd_chacha_rng_delete( NULL )==NULL ); /* invalid mem */
108+
FD_TEST( fd_chacha_rng_delete( rng )==_rng );
100109

101110
FD_LOG_NOTICE(( "pass" ));
102111
fd_halt();

0 commit comments

Comments
 (0)