Skip to content

Commit

Permalink
Merge pull request #103 from RadWolfie/update-global-tests-p2
Browse files Browse the repository at this point in the history
Update global tests (part 2)
  • Loading branch information
RadWolfie authored Feb 26, 2024
2 parents 5ea96a8 + c32e9c4 commit 5809a8e
Show file tree
Hide file tree
Showing 41 changed files with 388 additions and 605 deletions.
22 changes: 0 additions & 22 deletions src/assertions/common.c

This file was deleted.

28 changes: 20 additions & 8 deletions src/assertions/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@

#include <xboxkrnl/xboxkrnl.h>

BOOL assert_NTSTATUS_ex(
NTSTATUS,
NTSTATUS,
const char*,
int
);
#include "defines.h"

#define assert_NTSTATUS_ex( \
status, \
expected_status, \
api_name, \
line_number \
) \
if(status != expected_status) { \
print( \
" ERROR(line %d): Expected return status of function '%s' = 0x%x, got = 0x%x", \
line_number, \
api_name, \
expected_status, \
status \
); \
TEST_FAILED(); \
}
#define assert_NTSTATUS( \
status, \
expected_status, \
func_name \
api_name \
) \
assert_NTSTATUS_ex( \
status, \
expected_status, \
func_name, \
api_name, \
__LINE__ \
)
8 changes: 4 additions & 4 deletions src/assertions/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
" ERROR(line %d): Expected %s = 0x%x, Got = 0x%x") \
, func_line, varname, expected_var, check_var \
); \
test_passed = 0; \
TEST_FAILED(); \
}
#define GEN_CHECK(check_var, expected_var, varname) GEN_CHECK_EX(check_var, expected_var, varname, __LINE__)

Expand All @@ -30,7 +30,7 @@
" ERROR(line %d): Expected range %s = 0x%x-0x%x, Got = 0x%x") \
, func_line, varname, expected_var, expected_var + size, check_var \
); \
test_passed = 0; \
TEST_FAILED(); \
}
#define GEN_CHECK_RANGE(check_var, expected_var, size, varname) GEN_CHECK_RANGE_EX(check_var, expected_var, size, varname, __LINE__)

Expand All @@ -43,7 +43,7 @@
" ERROR(line %d): Expected array %s[%u] = 0x%x, Got = 0x%x") \
, func_line, varname, i, expected_var[i], check_var[i] \
); \
test_passed = 0; \
TEST_FAILED(); \
} \
}
#define GEN_CHECK_ARRAY(check_var, expected_var, size, varname) GEN_CHECK_ARRAY_EX(check_var, expected_var, size, varname, __LINE__)
Expand All @@ -57,7 +57,7 @@
" ERROR(line %d): Expected array %s[%u].%s = 0x%x, Got %s[%u].%s = 0x%x") \
, func_line, varname, i, #m_expected, var[i].m_expected, varname, i, #m_check, var[i].m_check \
); \
test_passed = 0; \
TEST_FAILED(); \
} \
}
#define GEN_CHECK_ARRAY_MEMBER(var, m_check, m_expected, size, varname) GEN_CHECK_ARRAY_MEMBER_EX(var, m_check, m_expected, size, varname, __LINE__)
22 changes: 0 additions & 22 deletions src/assertions/ex.c

This file was deleted.

27 changes: 14 additions & 13 deletions src/assertions/ex.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#pragma once

#include <xboxkrnl/xboxkrnl.h>
#include "defines.h"

BOOL assert_ERWLOCK_equals_ex(
PERWLOCK,
LONG,
ULONG,
ULONG,
ULONG,
const char*,
int
);
#define assert_ERWLOCK_equals( \
#define assert_ERWLOCK_equals_ex( \
ReadWriteLock, \
expected_LockCount, \
expected_WritersWaitingCount, \
expected_ReadersWaitingCount, \
expected_ReadersEntryCount, \
test_name \
line_number \
) \
GEN_CHECK_EX((ReadWriteLock)->LockCount, expected_LockCount, ".LockCount", line_number) \
GEN_CHECK_EX((ReadWriteLock)->WritersWaitingCount, expected_WritersWaitingCount, ".WritersWaitingCount", line_number) \
GEN_CHECK_EX((ReadWriteLock)->ReadersWaitingCount, expected_ReadersWaitingCount, ".ReadersWaitingCount", line_number) \
GEN_CHECK_EX((ReadWriteLock)->ReadersEntryCount, expected_ReadersEntryCount, ".ReadersEntryCount", line_number)
#define assert_ERWLOCK_equals( \
ReadWriteLock, \
expected_LockCount, \
expected_WritersWaitingCount, \
expected_ReadersWaitingCount, \
expected_ReadersEntryCount \
) \
assert_ERWLOCK_equals_ex( \
ReadWriteLock, \
expected_LockCount, \
expected_WritersWaitingCount, \
expected_ReadersWaitingCount, \
expected_ReadersEntryCount, \
test_name, \
__LINE__ \
)
15 changes: 0 additions & 15 deletions src/assertions/ke.c

This file was deleted.

13 changes: 8 additions & 5 deletions src/assertions/ke.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#pragma once

#include <xboxkrnl/xboxkrnl.h>
#include "defines.h"

BOOL assert_critical_region_ex(PKTHREAD, ULONG, const char*, int);
#define assert_critical_region( \
#define assert_critical_region_ex( \
thread, \
expected_Apc, \
test_name \
line_number \
) \
GEN_CHECK_EX(thread->KernelApcDisable, expected_Apc, ".KernelApcDisable", line_number)
#define assert_critical_region( \
thread, \
expected_Apc \
) \
assert_critical_region_ex( \
thread, \
expected_Apc, \
test_name, \
__LINE__ \
)
30 changes: 0 additions & 30 deletions src/assertions/rtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@
#include "rtl.h"
#include "defines.h"

BOOL assert_critical_section_equals_ex(
PRTL_CRITICAL_SECTION crit_section,
LONG expected_LockCount,
LONG expected_RecursionCount,
HANDLE expected_OwningThread,
const char* test_name,
int line_number)
{
ASSERT_HEADER

GEN_CHECK_EX(crit_section->LockCount, expected_LockCount, "LockCount", line_number);
GEN_CHECK_EX(crit_section->RecursionCount, expected_RecursionCount, "RecursionCount", line_number);
GEN_CHECK_EX(crit_section->OwningThread, expected_OwningThread, "OwningThread", line_number);

ASSERT_FOOTER(test_name)
}

BOOL assert_ansi_string_ex(
PANSI_STRING string,
USHORT expected_Length,
Expand Down Expand Up @@ -71,16 +54,3 @@ BOOL assert_unicode_string_ex(

ASSERT_FOOTER(test_name)
}

BOOL assert_rtl_compared_bytes_ex(
SIZE_T num_matching_bytes,
SIZE_T expected_matching_bytes,
const char* test_name,
int line_number)
{
ASSERT_HEADER

GEN_CHECK_EX(num_matching_bytes, expected_matching_bytes, "num_matching_bytes", line_number);

ASSERT_FOOTER(test_name)
}
41 changes: 15 additions & 26 deletions src/assertions/rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

#include <xboxkrnl/xboxkrnl.h>

BOOL assert_critical_section_equals_ex(
PRTL_CRITICAL_SECTION,
LONG,
LONG,
HANDLE,
const char*,
int
);
#define assert_critical_section_equals( \
#include "defines.h"

#define assert_critical_section_equals_ex( \
crit_section, \
expected_LockCount, \
expected_RecursionCount, \
expected_OwningThread, \
test_name \
line_number \
) \
GEN_CHECK_EX((crit_section)->LockCount, expected_LockCount, ".LockCount", line_number); \
GEN_CHECK_EX((crit_section)->RecursionCount, expected_RecursionCount, ".RecursionCount", line_number); \
GEN_CHECK_EX((crit_section)->OwningThread, expected_OwningThread, ".OwningThread", line_number)
#define assert_critical_section_equals( \
crit_section, \
expected_LockCount, \
expected_RecursionCount, \
expected_OwningThread \
) \
assert_critical_section_equals_ex( \
crit_section, \
expected_LockCount, \
expected_RecursionCount, \
expected_OwningThread, \
test_name, \
__LINE__ \
)

Expand All @@ -41,7 +43,7 @@ BOOL assert_ansi_string_ex(
expected_Buffer, \
test_name \
) \
assert_ansi_string_ex( \
test_passed &= assert_ansi_string_ex( \
string, \
expected_Length, \
expected_MaximumLength, \
Expand All @@ -65,24 +67,11 @@ BOOL assert_unicode_string_ex(
expected_Buffer, \
test_name \
) \
assert_unicode_string_ex( \
test_passed &= assert_unicode_string_ex( \
string, \
expected_Length, \
expected_MaximumLength, \
expected_Buffer, \
test_name, \
__LINE__ \
)

BOOL assert_rtl_compared_bytes_ex(SIZE_T, SIZE_T, const char*, int);
#define assert_rtl_compared_bytes( \
num_matching_bytes, \
expected_matching_bytes, \
test_name \
) \
assert_rtl_compared_bytes_ex( \
num_matching_bytes, \
expected_matching_bytes, \
test_name, \
__LINE__ \
)
2 changes: 1 addition & 1 deletion src/assertions/xc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BOOL assert_hashed_result_ex(
expected_result, \
test_name \
) \
assert_hashed_result_ex( \
test_passed &= assert_hashed_result_ex( \
input, \
len, \
expected_result, \
Expand Down
30 changes: 12 additions & 18 deletions src/tests/ex/ExAcquireReadWriteLockExclusive.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ TEST_FUNC(ExAcquireReadWriteLockExclusive)
ExInitializeReadWriteLock(&ReadWriteLock);

ExAcquireReadWriteLockExclusive(&ReadWriteLock);
test_passed = assert_ERWLOCK_equals(
&ReadWriteLock,
0, 0, 0, 0,
"Acquire exclusive lock on empty lock"
);
// Acquire exclusive lock on empty lock
assert_ERWLOCK_equals(&ReadWriteLock, 0, 0, 0, 0);
// Avoid spinning forever in the loop below.
if(!test_passed) {
if (TEST_IS_FAILED) {
TEST_END();
return;
}
Expand All @@ -85,35 +82,32 @@ TEST_FUNC(ExAcquireReadWriteLockExclusive)
HANDLE handle;
control_struct control = {&ReadWriteLock, 0, 0, 0, 0};
NTSTATUS result = PsCreateSystemThread(&handle, NULL, ExAcquireReadWriteLockExclusive_thread2, (void*)&control, 0);
if(result != STATUS_SUCCESS) {
if (result != STATUS_SUCCESS) {
print(" ERROR: did not create thread");
test_passed = 0;
TEST_FAILED();
TEST_END();
return;
}

test_passed = timed_poll_for_value((ULONG*)&ReadWriteLock.LockCount, 1);
if(!test_passed) {
if(TEST_IS_FAILED) {
print(" ERROR: LockCount did not equal 1\n");
test_passed = 0;
TEST_FAILED();
TEST_END();
return;
}
test_passed = assert_ERWLOCK_equals(
&ReadWriteLock,
1, 1, 0, 0,
"Second thread attempted to acquire the exclusive lock, incrementing WritersWaitingCount"
);
// Second thread attempted to acquire the exclusive lock, incrementing WritersWaitingCount
assert_ERWLOCK_equals(&ReadWriteLock, 1, 1, 0, 0);

if(control.thread2_status == 1) {
test_passed = 0;
TEST_FAILED();
print(" ERROR: The second thread was not supposed to write before the lock is released on the first thread.");
}
ExReleaseReadWriteLock(&ReadWriteLock);
test_passed = timed_poll_for_value(&control.thread2_status, 2);
if(!test_passed) {
if(TEST_IS_FAILED) {
print(" ERROR: thread2_status did not equal 2 before timing out.\n");
test_passed = 0;
TEST_FAILED();
}

TEST_END();
Expand Down
Loading

0 comments on commit 5809a8e

Please sign in to comment.