00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <basis/byte_array.h>
00016 #include <basis/chaos.h>
00017 #include <basis/function.h>
00018 #include <basis/guards.h>
00019 #include <basis/istring.h>
00020 #include <opsystem/application_shell.h>
00021 #include <loggers/console_logger.h>
00022 #include <opsystem/filename.h>
00023 #include <opsystem/shared_memory.h>
00024 #include <data_struct/static_memory_gremlin.h>
00025
00026 const int CHUNKING_SIZE = 20 * KILOBYTE;
00027
00028
00029 class test_shared_memory : public application_shell
00030 {
00031 public:
00032 test_shared_memory() : application_shell(class_name()) {}
00033 IMPLEMENT_CLASS_NAME("test_shared_memory");
00034 virtual int execute();
00035 };
00036
00037
00038 int zingle(int base)
00039 {
00040 return (base * 7 + 23108) % 255 + 1;
00041 }
00042
00043 int test_shared_memory::execute()
00044 {
00045 FUNCDEF("execute");
00046 const int chunk_size = 1208227;
00047 shared_memory biggy_chunk(chunk_size, const_cast<char *>(class_name()));
00048
00049 byte *mem = biggy_chunk.lock();
00050 if (!mem)
00051 deadly_error(class_name(), func,
00052 "allocation failure--could not create our shared memory chunk.");
00053 if (biggy_chunk.first_usage(mem, 100)) {
00054
00055 }
00056 biggy_chunk.unlock(mem);
00057
00058
00059 for (int i = 0; i < chunk_size; i += CHUNKING_SIZE) {
00060 byte *mem = biggy_chunk.lock();
00061
00062 if (!mem[i]) {
00063
00064 for (int j = 0; j < CHUNKING_SIZE; j++) {
00065
00066 if (mem[i + j])
00067 deadly_error(class_name(), func,
00068 "value failure--non-zero value in range where zero is required.");
00069
00070 mem[i + j] = zingle(i + j);
00071 }
00072
00073 } else {
00074
00075 for (int j = 0; j < CHUNKING_SIZE; j++) {
00076
00077 if (mem[i + j] != zingle(i + j))
00078 deadly_error(class_name(), func,
00079 "value failure--this range has an incorrect value.");
00080 }
00081
00082
00083 biggy_chunk.unlock(mem);
00084 continue;
00085 }
00086
00087 biggy_chunk.unlock(mem);
00088
00089
00090 int nap_length = randomizer().inclusive(10, 300);
00091 portable::sleep_ms(nap_length);
00092 }
00093
00094 guards::alert_message("shared_memory:: works for those functions tested.\n");
00095 return 0;
00096 }
00097
00098 HOOPLE_MAIN(test_shared_memory, )
00099