forked from SynthstromAudible/DelugeFirmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
containers: move open hash table tests to actual test binary (Synthst…
- Loading branch information
1 parent
96a78f8
commit a59e087
Showing
12 changed files
with
360 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "CppUTest/TestHarness.h" | ||
|
||
#include "util/container/hashtable/open_addressing_hash_table.h" | ||
|
||
TEST_GROUP(OpenHashTableTest) { | ||
}; | ||
|
||
constexpr const uint32_t NUM_ELEMENTS_TO_ADD = 64; | ||
|
||
template <typename HashTable> | ||
void runTest(HashTable& table) { | ||
uint32_t elementsAdded[NUM_ELEMENTS_TO_ADD]; | ||
int32_t numElementsAdded = 0; | ||
|
||
// Add a bunch of elements | ||
while (numElementsAdded < NUM_ELEMENTS_TO_ADD) { | ||
// Don't allow 0 - we'll use that for special test. Or 0xFF, cos that means empty | ||
elementsAdded[numElementsAdded] = numElementsAdded + 1; | ||
|
||
CHECK(table.insert(elementsAdded[numElementsAdded])); | ||
numElementsAdded++; | ||
} | ||
|
||
CHECK_EQUAL(NUM_ELEMENTS_TO_ADD, table.numElements); | ||
|
||
// See if it'll let us remove an element that doesn't exist | ||
CHECK_FALSE(table.remove(0)); | ||
|
||
// Clean up elements | ||
for (unsigned int& i : elementsAdded) { | ||
CHECK(table.remove(i)); | ||
} | ||
|
||
CHECK_EQUAL(0, table.numElements); | ||
|
||
// See if it'll let us remove an element that doesn't exist | ||
CHECK_FALSE(table.remove(0)); | ||
} | ||
|
||
TEST(OpenHashTableTest, test8bit) { | ||
OpenAddressingHashTableWith8bitKey table; | ||
runTest(table); | ||
} | ||
|
||
TEST(OpenHashTableTest, test16bit) { | ||
OpenAddressingHashTableWith16bitKey table; | ||
runTest(table); | ||
} | ||
|
||
TEST(OpenHashTableTest, test32bit) { | ||
OpenAddressingHashTableWith32bitKey table; | ||
runTest(table); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace AudioEngine { | ||
bool bypassCulling{false}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#include "memory/general_memory_allocator.h" | ||
#include "CppUTest/TestHarness.h" | ||
#include <cstdlib> | ||
|
||
// Fake allocator object | ||
GeneralMemoryAllocator allocator; | ||
|
||
class MockMemoryAllocator { | ||
public: | ||
void* alloc(uint32_t requiredSize, bool mayUseOnChipRam, bool makeStealable, void* thingNotToStealFrom) { | ||
return malloc(requiredSize); | ||
} | ||
|
||
void dealloc(void* address) { free(address); } | ||
|
||
void* allocExternal(uint32_t requiredSize) { return malloc(requiredSize); } | ||
|
||
void deallocExternal(void* address) { free(address); } | ||
|
||
uint32_t shortenRight(void* address, uint32_t newSize) { | ||
/* noop on mock allocator */ | ||
/// TODO: integrate some sort of sanity checking to make this actually check whether hte call is valid | ||
return 0; | ||
} | ||
|
||
uint32_t shortenLeft(void* address, uint32_t amountToShorten, uint32_t numBytesToMoveRightIfSuccessful = 0) { | ||
// TODO: implementing this requires actually tracking allocations so we know the size. | ||
CHECK(false); | ||
return -1; | ||
} | ||
|
||
void extend(void* address, uint32_t minAmountToExtend, uint32_t idealAmountToExtend, | ||
uint32_t* getAmountExtendedLeft, uint32_t* getAmountExtendedRight, void* thingNotToStealFrom = NULL) { | ||
// TODO: implementing this requires actually tracking allocations so we know the starting size. | ||
CHECK(false); | ||
} | ||
|
||
uint32_t extendRightAsMuchAsEasilyPossible(void* address) { | ||
// TODO: implementing this requires actually tracking allocations so we know the starting size. | ||
CHECK(false); | ||
return -1; | ||
} | ||
|
||
uint32_t getAllocatedSize(void* address) { | ||
// TODO: implementing this requires actually tracking allocations so we know the starting size. | ||
CHECK(false); | ||
return -1; | ||
} | ||
|
||
void checkStack(char const* caller) { /* noop in tests */ | ||
} | ||
|
||
int32_t getRegion(void* address) { | ||
// TODO: we should expose an API to allow mocking this | ||
return 0; | ||
} | ||
}; | ||
|
||
MockMemoryAllocator mockAllocator; | ||
|
||
MemoryRegion::MemoryRegion() = default; | ||
GeneralMemoryAllocator::GeneralMemoryAllocator()= default; | ||
|
||
void* GeneralMemoryAllocator::alloc(uint32_t requiredSize, bool mayUseOnChipRam, bool makeStealable, | ||
void* thingNotToStealFrom) { | ||
return mockAllocator.alloc(requiredSize, mayUseOnChipRam, makeStealable, thingNotToStealFrom); | ||
} | ||
|
||
void GeneralMemoryAllocator::dealloc(void* address) { | ||
return mockAllocator.dealloc(address); | ||
} | ||
|
||
void* GeneralMemoryAllocator::allocExternal(uint32_t requiredSize) { | ||
return mockAllocator.allocExternal(requiredSize); | ||
} | ||
|
||
void GeneralMemoryAllocator::deallocExternal(void* address) { | ||
return mockAllocator.deallocExternal(address); | ||
} | ||
|
||
uint32_t GeneralMemoryAllocator::shortenRight(void* address, uint32_t newSize) { | ||
return mockAllocator.shortenRight(address, newSize); | ||
} | ||
|
||
uint32_t GeneralMemoryAllocator::shortenLeft(void* address, uint32_t amountToShorten, | ||
uint32_t numBytesToMoveRightIfSuccessful) { | ||
return mockAllocator.shortenLeft(address, amountToShorten, numBytesToMoveRightIfSuccessful); | ||
} | ||
|
||
void GeneralMemoryAllocator::extend(void* address, uint32_t minAmountToExtend, uint32_t idealAmountToExtend, | ||
uint32_t* getAmountExtendedLeft, uint32_t* getAmountExtendedRight, | ||
void* thingNotToStealFrom) { | ||
return mockAllocator.extend(address, minAmountToExtend, idealAmountToExtend, getAmountExtendedLeft, | ||
getAmountExtendedRight, thingNotToStealFrom); | ||
} | ||
|
||
uint32_t GeneralMemoryAllocator::extendRightAsMuchAsEasilyPossible(void* address) { | ||
return mockAllocator.extendRightAsMuchAsEasilyPossible(address); | ||
} | ||
|
||
uint32_t GeneralMemoryAllocator::getAllocatedSize(void* address) { | ||
return mockAllocator.getAllocatedSize(address); | ||
} | ||
|
||
void GeneralMemoryAllocator::checkStack(char const* caller) { | ||
return mockAllocator.checkStack(caller); | ||
} | ||
|
||
int32_t GeneralMemoryAllocator::getRegion(void* address) { | ||
return mockAllocator.getRegion(address); | ||
} | ||
|
||
extern "C" { | ||
|
||
void* delugeAlloc(unsigned int requiredSize, bool mayUseOnChipRam) { | ||
return GeneralMemoryAllocator::get().alloc(requiredSize, mayUseOnChipRam, false, nullptr); | ||
} | ||
|
||
void delugeDealloc(void* address) { | ||
GeneralMemoryAllocator::get().dealloc(address); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <cstdint> | ||
int32_t __sdram_bss_end = 0; | ||
int32_t program_stack_start = 0; | ||
int32_t program_stack_end = 0; | ||
int32_t __heap_start = 0; | ||
uint32_t currentUIMode = 0; | ||
|
||
#define NUM_ENCODERS 6 | ||
#define NUM_FUNCTION_ENCODERS 4 | ||
#define ENCODER_SCROLL_X 1 | ||
#define ENCODER_SCROLL_Y 0 | ||
#define ENCODER_TEMPO 3 | ||
#define ENCODER_SELECT 2 | ||
#define ENCODER_MOD_0 5 | ||
#define ENCODER_MOD_1 4 |
Oops, something went wrong.