+#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define INDIRECT_SHIFT 8
int rand_int(int n) {
- return (int)((long long)rand() * n / (RAND_MAX + 1LL));
+ assert(sizeof(long) > sizeof(int));
+ return (int)((long)rand() * n / (RAND_MAX + 1L));
}
int bytes_to_blocks(int size) {
#define TRANSFER_SIZE 821 // a prime number somewhat near the block size
-int rand_int(int n) {
- return (int)((long long)rand() * n / (RAND_MAX + 1LL));
-}
-
bool hash_init(int file, struct cinode *inode, int base, int limit) {
int count;
for (int ptr = base; (count = limit - ptr) > 0; ptr += count) {
count = TRANSFER_SIZE;
uint8_t buf[TRANSFER_SIZE];
- for (int i = 0; i < count; ++i) {
- long long hash = file * 17 + (i + ptr) * 29;
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffLL) + (hash >> 16);
- hash = (hash & 0xffLL) + (hash >> 8);
- hash = (hash & 0xffLL) + (hash >> 8);
- buf[i] = (uint8_t)hash;
- }
+ for (int i = 0; i < count; ++i)
+ buf[i] = (uint8_t)(file * 17 + (i + ptr) * 29);
udata.u_base = (char *)buf;
udata.u_count = count;
udata.u_error = 0;
rassert(readi(inode) == count && udata.u_error == 0);
- for (int i = 0; i < count; ++i) {
- long long hash = file * 17 + (i + ptr) * 29;
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffLL) + (hash >> 16);
- hash = (hash & 0xffLL) + (hash >> 8);
- hash = (hash & 0xffLL) + (hash >> 8);
- rassert(buf[i] == (uint8_t)hash);
- }
+ for (int i = 0; i < count; ++i)
+ rassert(buf[i] == (uint8_t)(file * 17 + (i + ptr) * 29));
}
}
#!/bin/sh
echo "generate test script"
-./inode_test_gen 64 16128 16384 4096 >inode_test.txt
+./inode_test_gen 64 16128 1024 4096 >inode_test.txt
echo "run test script"
rm -f fs.bin
+#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "rassert.h"
int rand_int(int n) {
- return (int)((long long)rand() * n / (RAND_MAX + 1LL));
+ assert(sizeof(long) > sizeof(int));
+ return (int)((long)rand() * n / (RAND_MAX + 1L));
}
int main(int argc, char **argv) {
void hash_init(int item, int base, int size, int offset) {
for (int i = 0; i < size; ++i) {
- long long hash = item * 17 + (i + offset) * 29;
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffLL) + (hash >> 32);
rassert(mem[base + i] == 0xaaaaaaaa);
- mem[base + i] = (int)hash;
+ mem[base + i] = item * 17 + (i + offset) * 29;
}
}
void hash_verify(int item, int base, int size, int offset) {
for (int i = 0; i < size; ++i) {
- long long hash = item * 17 + (i + offset) * 29;
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- rassert(mem[base + i] == (int)hash);
+ rassert(mem[base + i] == item * 17 + (i + offset) * 29);
mem[base + i] = 0xaaaaaaaa;
}
}
+#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#endif
int rand_int(int n) {
- return (int)((long long)rand() * n / (RAND_MAX + 1LL));
+ assert(sizeof(long) > sizeof(int));
+ return (int)((long)rand() * n / (RAND_MAX + 1L));
}
long rand_long(long n) {
- return (long)((long long)rand() * n / (RAND_MAX + 1LL));
+ assert(sizeof(long) > sizeof(int));
+ return (int)((long)rand() * n / (RAND_MAX + 1L));
}
int main(int argc, char **argv) {
void core_hash_init(int process, long base, long size, long offset) {
long i, addr;
- long long hash;
//printf("core_hash_init %d %ld(%d) %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT), offset, (int)(offset >> BLOCK_SHIFT));
for (i = 0L; i < size; ++i) {
(core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
(addr & (BLOCK_SIZE - 1));
#endif /* INDIRECT_CORE */
- hash = process * 17 + (i + offset) * 29;
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffLL) + (hash >> 16);
- hash = (hash & 0xffLL) + (hash >> 8);
- hash = (hash & 0xffLL) + (hash >> 8);
rassert(core_block_mem[addr] == 0xaa);
- core_block_mem[addr] = (uint8_t)hash;
+ core_block_mem[addr] = (uint8_t)(process * 17 + (i + offset) * 29);
}
}
void core_hash_verify(int process, long base, long size, long offset) {
long i, addr;
- long long hash;
//printf("core_hash_verify %d %ld(%d) %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT), offset, (int)(offset >> BLOCK_SHIFT));
for (i = 0L; i < size; ++i) {
(core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
(addr & (BLOCK_SIZE - 1));
#endif /* INDIRECT_CORE */
- hash = process * 17 + (i + offset) * 29;
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffLL) + (hash >> 16);
- hash = (hash & 0xffLL) + (hash >> 8);
- hash = (hash & 0xffLL) + (hash >> 8);
- rassert(core_block_mem[addr] == (uint8_t)hash);
+ rassert(
+ core_block_mem[addr] == (uint8_t)(process * 17 + (i + offset) * 29)
+ );
core_block_mem[addr] = 0xaa;
}
}
void swap_hash_verify(int process, long base, long size, long offset) {
long i, addr;
- long long hash;
//printf("swap_hash_verify %d %ld(%d) %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT), offset, (int)(offset >> BLOCK_SHIFT));
for (i = 0L; i < size; ++i) {
(swap_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
(addr & (BLOCK_SIZE - 1));
#endif /* INDIRECT_SWAP */
- hash = process * 17 + (i + offset) * 29;
- hash = (hash & 0xffffffffLL) + (hash >> 32);
- hash = (hash & 0xffffLL) + (hash >> 16);
- hash = (hash & 0xffLL) + (hash >> 8);
- hash = (hash & 0xffLL) + (hash >> 8);
- rassert(swap_block_mem[addr] == (uint8_t)hash);
+ rassert(
+ swap_block_mem[addr] == (uint8_t)(process * 17 + (i + offset) * 29)
+ );
swap_block_mem[addr] = 0xaa;
}
}