MainTree/tests/internal/shadow-lookup/main.c

56 lines
1.5 KiB
C

#include <shadow.h>
#include <context.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
MtShadowRegistry registry;
void cleanup_and_exit(int status_code)
{
mt_cleanup_shadow_registry(&registry);
}
void signal_handler(int number)
{
printf("FAIL: The program crashed because of a memory access error!\n");
exit(-8);
}
int main(int argc, char **argv)
{
signal(SIGSEGV, &signal_handler);
registry = mt_create_shadow_registry(NULL);
MtShadow *original_1 = mt_create_shadow(&registry);
MtShadow *lookedup_1 = mt_lookup_shadow(&registry, original_1->identifier);
MtShadow *original_2 = mt_create_shadow(&registry);
MtShadow *lookedup_2 = mt_lookup_shadow(&registry, original_2->identifier);
if(original_1 != lookedup_1)
{
puts("FAIL: In test case 1, the original shadow doesn't match the looked-up one.");
printf("O %p : L %p\n", original_1, lookedup_1);
cleanup_and_exit(-1);
}
if(original_2 != lookedup_2)
{
puts("FAIL: In test case 2, the original shadow doesn't match the looked-up one.");
printf("O %p : L %p\n", original_2, lookedup_2);
cleanup_and_exit(-2);
}
if(original_1 == original_2)
{
puts("FAIL: In test case 3, the first original shadow matches the second!");
cleanup_and_exit(-3);
}
if(lookedup_1 == lookedup_2)
{
puts("FAIL: In test case 3, the first looked-up shadow matches the second!");
cleanup_and_exit(-4);
}
puts("Success.");
cleanup_and_exit(0);
return 0;
}