Пример #1
0
Файл: ftest03.c Проект: kraj/ltp
/*
 *	Inject misc syscalls into the thing.
 */
static void domisc(int me, int fd, char *bits)
{
	int chunk;
	struct stat sb;

	if (type > m_fstat)
		type = m_fsync;

	switch (type) {
	case m_fsync:
		if (fsync(fd) < 0) {
			tst_brkm(TFAIL, NULL, "\tTest[%d]: fsync error %d.",
				 me,
				 errno);
		}
		break;
	case m_trunc:
		chunk = rand() % (file_max / csize);
		file_max = CHUNK(chunk);
		last_trunc = file_max;
		if (tr_flag) {
			if (ftruncate(fd, file_max) < 0) {
				tst_brkm(TFAIL,
					 NULL,
					 "\tTest[%d]: ftruncate error %d @ 0x%x.",
					 me, errno, file_max);
			}
			tr_flag = 0;
		} else {
			if (truncate(test_name, file_max) < 0) {
				tst_brkm(TFAIL,
					 NULL,
					 "\tTest[%d]: truncate error %d @ 0x%x.",
					 me, errno, file_max);
			}
			tr_flag = 1;
		}
		for (; chunk % 8 != 0; chunk++)
			bits[chunk / 8] &= ~(1 << (chunk % 8));
		for (; chunk < nchunks; chunk += 8)
			bits[chunk / 8] = 0;
		break;
	case m_fstat:
		if (fstat(fd, &sb) < 0) {
			tst_brkm(TFAIL, NULL, "\tTest[%d]: fstat() error %d.",
				 me,
				 errno);
		}
		if (sb.st_size != file_max) {
			tst_brkm(TFAIL,
				 NULL, "\tTest[%d]: fstat() mismatch; st_size=%"
				 PRIx64 ",file_max=%x.", me,
				 (int64_t) sb.st_size, file_max);
		}
		break;
	}

	++misc_cnt[type];
	++type;
}
Пример #2
0
void tenkListChunks(PVOID heapHandle) {
	struct HPool			*heap;
	struct DestroyStruct	dStruct;
	struct HeapChunk		*curChunk;
	ULONG					i;

	heap = getHeap(&heapModel, heapHandle);
	dprintf("[T] Currently tracking %d chunks for heap 0x%08x\n", 
			heap->numChunks, heap->base);
	
	i = heap->inUseHead;
	while (i != NULLNODE) {
		if (CHUNK(i).inUse) {
			dprintf("\tAddress: 0x%08x\tSize: 0x%08x", CHUNK(i).addr, CHUNK(i).size);
			dprintf("\tFlags: 0x%08x\t%s\n\n", CHUNK(i).flags, 
					(CHUNK(i).free)?"FREE'D":"IN USE");
		}
		i = CHUNK(i).nextInUse;
	}

	if (heap->numChunks == 0) {
		dStruct.heapHandle	= heap->base;
		heapDestroy(&heapModel, &dStruct);
	}
}
Пример #3
0
void tenkValidate(PVOID heapHandle) {
	struct HPool            *heap;
    struct DestroyStruct    dStruct;
    struct HeapChunk        *curChunk;
	ULONG					chunkPtr;
    ULONG                   i, nextIndex;
	BOOL					screwed = FALSE;

	heap = getHeap(&heapModel, heapHandle);

	i = heap->inUseHead;
	while (i != NULLNODE) {
		if (CHUNK(i).free) {
			// CHUNK(i).nextInUse must be equal to the next ptr
			if(!ReadMemory((ULONG64)(CHUNK(i).addr)+4, (PVOID) &chunkPtr, 4, NULL)) {
				dprintf("[T] Unable to read memory at address 0x%08x\n!");
				return;
			}

			// Find next free chunk - continue if there are no more
			nextIndex = CHUNK(i).nextInUse;
			while (nextIndex != NULLNODE && !(CHUNK(nextIndex).free))
				nextIndex = CHUNK(nextIndex).nextInUse;
			if (nextIndex == NULLNODE) {
				i = CHUNK(i).nextInUse;
				continue;
			}

			// Validate next free chunk
			if (CHUNK(nextIndex).addr != (PVOID) chunkPtr) {
				dprintf("[T] Corruped next pointer for chunk at 0x%08x\n", CHUNK(i).addr);
				dprintf(">\tGot: 0x%08x\tExpected: 0x%08x\n", chunkPtr, CHUNK(nextIndex).addr);
				screwed = TRUE;
			}
			
			// next free chunk prev, must equal CHUNK(i).addr
			if(!ReadMemory((ULONG64)CHUNK(nextIndex).addr, (PVOID) &chunkPtr, 4, NULL)) {
                dprintf("[T] Unable to read memory at address 0x%08x\n!");
                return; 
            }
			if ((PVOID) chunkPtr != CHUNK(i).addr) {
                dprintf("[T] Corruped prev pointer for chunk at 0x%08x\n", CHUNK(nextIndex).addr);
                dprintf(">\tGot: 0x%08x\tExpected: 0x%08x\n", chunkPtr, CHUNK(i).addr);
				screwed = TRUE;
			}
		
		
		} else {
		}
		i = CHUNK(i).nextInUse;
	}
	
	dprintf("[T] Validation complete: ");
	if (!screwed)
		dprintf("all known free chunks are correct\n");
	else
		dprintf("errors found\n");
}
Пример #4
0
static void dotest(int testers, int me, int fd)
{
	char *bits, *buf;
	char val, val0;
	int count, collide, chunk, whenmisc, xfr, i;

	/* Stuff for the readv call */
	struct iovec r_iovec[MAXIOVCNT];
	int r_ioveclen;

	/* Stuff for the writev call */
	struct iovec val0_iovec[MAXIOVCNT];
	struct iovec val_iovec[MAXIOVCNT];
	int w_ioveclen;

	nchunks = max_size / (testers * csize);
	whenmisc = 0;

	if ((bits = malloc((nchunks + 7) / 8)) == NULL) {
		tst_resm(TBROK, "\tmalloc failed(bits)");
		tst_exit();
	}

	if ((buf = (malloc(csize))) == NULL) {
		tst_resm(TBROK, "\tmalloc failed(buf)");
		tst_exit();
	}

	/* Allocate memory for the iovec buffers and init the iovec arrays */
	r_ioveclen = w_ioveclen = csize / MAXIOVCNT;

	/* Please note that the above statement implies that csize
	 * be evenly divisible by MAXIOVCNT.
	 */
	for (i = 0; i < MAXIOVCNT; i++) {
		if ((r_iovec[i].iov_base = malloc(r_ioveclen)) == NULL) {
			tst_resm(TBROK, "\tmalloc failed(iov_base)");
			tst_exit();
		}
		r_iovec[i].iov_len = r_ioveclen;

		/* Allocate unused memory areas between all the buffers to
		 * make things more diffult for the OS.
		 */
		if (malloc((i + 1) * 8) == NULL) {
			tst_resm(TBROK, "\tmalloc failed((i+1)*8)");
			tst_exit();
		}

		if ((val0_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) {
			tst_resm(TBROK, "\tmalloc failed(val0_iovec)");
			tst_exit();
		}

		val0_iovec[i].iov_len = w_ioveclen;

		if (malloc((i + 1) * 8) == NULL) {
			tst_resm(TBROK, "\tmalloc failed((i+1)*8)");
			tst_exit();
		}

		if ((val_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) {
			tst_resm(TBROK, "\tmalloc failed(iov_base)");
			tst_exit();
		}
		val_iovec[i].iov_len = w_ioveclen;

		if (malloc((i + 1) * 8) == NULL) {
			tst_resm(TBROK, "\tmalloc failed(((i+1)*8)");
			tst_exit();
		}
	}

	/*
	 * No init sectors; file-sys makes 0 to start.
	 */
	val = (64 / testers) * me + 1;
	val0 = 0;

	/*
	 * For each iteration:
	 *      zap bits array
	 *      loop:
	 *              pick random chunk, read it.
	 *              if corresponding bit off {
	 *                      verify == 0. (sparse file)
	 *                      ++count;
	 *              } else
	 *                      verify == val.
	 *              write "val" on it.
	 *              repeat until count = nchunks.
	 *      ++val.
	 */
	srand(getpid());

	if (misc_intvl)
		whenmisc = NEXTMISC;

	while (iterations-- > 0) {
		for (i = 0; i < NMISC; i++)
			misc_cnt[i] = 0;
		memset(bits, 0, (nchunks + 7) / 8);
		/* Have to fill the val0 and val iov buffers in a different manner
		 */
		for (i = 0; i < MAXIOVCNT; i++) {
			memset(val0_iovec[i].iov_base, val0,
			       val0_iovec[i].iov_len);
			memset(val_iovec[i].iov_base, val,
			       val_iovec[i].iov_len);

		}

		count = 0;
		collide = 0;

		while (count < nchunks) {
			chunk = rand() % nchunks;
			/*
			 * Read it.
			 */
			if (lseek64(fd, CHUNK(chunk), 0) < 0) {
				tst_resm(TFAIL,
					 "\tTest[%d]: lseek64(0) fail at %"
					 PRIx64 "x, errno = %d.", me,
					 CHUNK(chunk), errno);
				tst_exit();
			}
			if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) {
				tst_resm(TFAIL,
					 "\tTest[%d]: readv fail at %" PRIx64
					 "x, errno = %d.", me, CHUNK(chunk),
					 errno);
				tst_exit();
			}
			/*
			 * If chunk beyond EOF just write on it.
			 * Else if bit off, haven't seen it yet.
			 * Else, have.  Verify values.
			 */
			if (xfr == 0) {
				bits[chunk / 8] |= (1 << (chunk % 8));
			} else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) {
				if (xfr != csize) {
					tst_resm(TFAIL,
						 "\tTest[%d]: xfr=%d != %d, zero read.",
						 me, xfr, csize);
					tst_exit();
				}
				for (i = 0; i < MAXIOVCNT; i++) {
					if (memcmp
					    (r_iovec[i].iov_base,
					     val0_iovec[i].iov_base,
					     r_iovec[i].iov_len)) {
						tst_resm(TFAIL,
							 "\tTest[%d] bad verify @ 0x%"
							 PRIx64
							 " for val %d count %d xfr %d.",
							 me, CHUNK(chunk), val0,
							 count, xfr);
						ft_dumpiov(&r_iovec[i]);
						ft_dumpbits(bits,
							    (nchunks + 7) / 8);
						tst_exit();
					}
				}
				bits[chunk / 8] |= (1 << (chunk % 8));
				++count;
			} else {
				if (xfr != csize) {
					tst_resm(TFAIL,
						 "\tTest[%d]: xfr=%d != %d, val read.",
						 me, xfr, csize);
					tst_exit();
				}
				++collide;
				for (i = 0; i < MAXIOVCNT; i++) {
					if (memcmp
					    (r_iovec[i].iov_base,
					     val_iovec[i].iov_base,
					     r_iovec[i].iov_len)) {
						tst_resm(TFAIL,
							 "\tTest[%d] bad verify @ 0x%"
							 PRIx64
							 " for val %d count %d xfr %d.",
							 me, CHUNK(chunk), val,
							 count, xfr);
						ft_dumpiov(&r_iovec[i]);
						ft_dumpbits(bits,
							    (nchunks + 7) / 8);
						tst_exit();
					}
				}
			}
			/*
			 * Write it.
			 */
			if (lseek64(fd, -xfr, 1) < 0) {
				tst_resm(TFAIL,
					 "\tTest[%d]: lseek64(1) fail at %"
					 PRIx64 ", errno = %d.", me,
					 CHUNK(chunk), errno);
				tst_exit();
			}
			if ((xfr =
			     writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) {
				if (errno == ENOSPC) {
					tst_resm(TFAIL,
						 "\tTest[%d]: no space, exiting.",
						 me);
					fsync(fd);
					tst_exit();
				}
				tst_resm(TFAIL,
					 "\tTest[%d]: writev fail at %" PRIx64
					 "x xfr %d, errno = %d.", me,
					 CHUNK(chunk), xfr, errno);
				tst_exit();
			}
			/*
			 * If hit "misc" interval, do it.
			 */
			if (misc_intvl && --whenmisc <= 0) {
				domisc(me, fd);
				whenmisc = NEXTMISC;
			}
			if (count + collide > 2 * nchunks)
				break;
		}

		/*
		 * End of iteration, maybe before doing all chunks.
		 */

		if (count < nchunks) {
			//tst_resm(TINFO, "\tTest{%d} val %d stopping @ %d, collide = {%d}.",
			//              me, val, count, collide);
			for (i = 0; i < nchunks; i++) {
				if ((bits[i / 8] & (1 << (i % 8))) == 0) {
					if (lseek64(fd, CHUNK(i), 0) <
					    (off64_t) 0) {
						tst_resm(TFAIL,
							 "\tTest[%d]: lseek64 fail at %"
							 PRIx64
							 "x, errno = %d.", me,
							 CHUNK(i), errno);
						tst_exit();
					}
					if (writev(fd, &val_iovec[0], MAXIOVCNT)
					    != csize) {
						tst_resm(TFAIL,
							 "\tTest[%d]: writev fail at %"
							 PRIx64
							 "x, errno = %d.", me,
							 CHUNK(i), errno);
						tst_exit();
					}
				}
			}
		}

		fsync(fd);
		++misc_cnt[m_fsync];
		//tst_resm(TINFO, "\tTest[%d] val %d done, count = %d, collide = %d.",
		//              me, val, count, collide);
		//for (i = 0; i < NMISC; i++)
		//      tst_resm(TINFO, "\t\tTest[%d]: %d %s's.", me, misc_cnt[i], m_str[i]);
		val0 = val++;
	}
}
Пример #5
0
static void dotest(int testers, int me, int fd)
{
	char *bits, *hold_bits;
	char val;
	int chunk, whenmisc, xfr, count, collide, i;

	/* Stuff for the readv call */
	struct iovec r_iovec[MAXIOVCNT];
	int r_ioveclen;

	/* Stuff for the writev call */
	struct iovec val_iovec[MAXIOVCNT];
	struct iovec zero_iovec[MAXIOVCNT];
	int w_ioveclen;

	nchunks = max_size / csize;
	whenmisc = 0;

	if ((bits = malloc((nchunks + 7) / 8)) == 0) {
		tst_resm(TBROK, "\tmalloc failed");
		tst_exit();
	}

	if ((hold_bits = malloc((nchunks + 7) / 8)) == 0) {
		tst_resm(TBROK, "\tmalloc failed");
		tst_exit();
	}

	/*Allocate memory for the iovec buffers and init the iovec arrays */
	r_ioveclen = w_ioveclen = csize / MAXIOVCNT;

	/* Please note that the above statement implies that csize
	 * be evenly divisible by MAXIOVCNT.
	 */
	for (i = 0; i < MAXIOVCNT; i++) {
		if ((r_iovec[i].iov_base = calloc(r_ioveclen, 1)) == 0) {
			tst_brkm(TBROK, NULL, "\tmalloc failed");
			/* tst_exit(); */
		}
		r_iovec[i].iov_len = r_ioveclen;

		/* Allocate unused memory areas between all the buffers to
		 * make things more diffult for the OS.
		 */
		if (malloc((i + 1) * 8) == NULL) {
			tst_brkm(TBROK, NULL, "\tmalloc failed");
		}

		if ((val_iovec[i].iov_base = calloc(w_ioveclen, 1)) == 0) {
			tst_resm(TBROK, "\tmalloc failed");
			tst_exit();
		}

		val_iovec[i].iov_len = w_ioveclen;

		if (malloc((i + 1) * 8) == NULL) {
			tst_resm(TBROK, "\tmalloc failed");
			tst_exit();
		}

		if ((zero_iovec[i].iov_base = calloc(w_ioveclen, 1)) == 0) {
			tst_resm(TBROK, "\tmalloc failed");
			tst_exit();
		}

		zero_iovec[i].iov_len = w_ioveclen;

		if (malloc((i + 1) * 8) == NULL) {
			tst_resm(TBROK, "\tmalloc failed");
			tst_exit();
		}
	}
	/*
	 * No init sectors; allow file to be sparse.
	 */
	val = (64 / testers) * me + 1;

	/*
	 * For each iteration:
	 *      zap bits array
	 *      loop
	 *              pick random chunk, read it.
	 *              if corresponding bit off {
	 *                      verify = 0. (sparse file)
	 *                      ++count;
	 *              } else
	 *                      verify = val.
	 *              write "val" on it.
	 *              repeat unitl count = nchunks.
	 *      ++val.
	 */

	srand(getpid());

	if (misc_intvl)
		whenmisc = NEXTMISC;

	while (iterations-- > 0) {

		for (i = 0; i < NMISC; i++)
			misc_cnt[i] = 0;

		ftruncate(fd, 0);
		file_max = 0;
		memset(bits, 0, (nchunks + 7) / 8);
		memset(hold_bits, 0, (nchunks + 7) / 8);

		/* Have to fill the val and zero iov buffers in a different manner
		 */
		for (i = 0; i < MAXIOVCNT; i++) {
			memset(val_iovec[i].iov_base, val,
			       val_iovec[i].iov_len);
			memset(zero_iovec[i].iov_base, 0,
			       zero_iovec[i].iov_len);

		}

		count = 0;
		collide = 0;

		while (count < nchunks) {
			chunk = rand() % nchunks;
			/*
			 * Read it.
			 */
			if (lseek(fd, CHUNK(chunk), 0) < 0) {
				tst_resm(TFAIL,
					 "\tTest[%d]: lseek(0) fail at %x, errno = %d.",
					 me, CHUNK(chunk), errno);
				tst_exit();
			}
			if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) {
				tst_resm(TFAIL,
					 "\tTest[%d]: readv fail at %x, errno = %d.",
					 me, CHUNK(chunk), errno);
				tst_exit();
			}
			/*
			 * If chunk beyond EOF just write on it.
			 * Else if bit off, haven't seen it yet.
			 * Else, have.  Verify values.
			 */
			if (CHUNK(chunk) >= file_max) {
				bits[chunk / 8] |= (1 << (chunk % 8));
				++count;
			} else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) {
				if (xfr != csize) {
					tst_resm(TFAIL,
						 "\tTest[%d]: xfr=%d != %d, zero read.",
						 me, xfr, csize);
					tst_exit();
				}
				for (i = 0; i < MAXIOVCNT; i++) {
					if (memcmp
					    (r_iovec[i].iov_base,
					     zero_iovec[i].iov_base,
					     r_iovec[i].iov_len)) {
						tst_resm(TFAIL,
							 "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d file_max 0x%x, should be 0.",
							 me, CHUNK(chunk), val,
							 count, xfr, file_max);
						tst_resm(TINFO,
							 "\tTest[%d]: last_trunc = 0x%x.",
							 me, last_trunc);
						sync();
						ft_dumpiov(&r_iovec[i]);
						ft_dumpbits(bits,
							    (nchunks + 7) / 8);
						ft_orbits(hold_bits, bits,
							  (nchunks + 7) / 8);
						tst_resm(TINFO, "\tHold ");
						ft_dumpbits(hold_bits,
							    (nchunks + 7) / 8);
						tst_exit();
					}
				}
				bits[chunk / 8] |= (1 << (chunk % 8));
				++count;
			} else {
				if (xfr != csize) {
					tst_resm(TFAIL,
						 "\tTest[%d]: xfr=%d != %d, val read.",
						 me, xfr, csize);
					tst_exit();
				}
				++collide;
				for (i = 0; i < MAXIOVCNT; i++) {
					if (memcmp
					    (r_iovec[i].iov_base,
					     val_iovec[i].iov_base,
					     r_iovec[i].iov_len)) {
						tst_resm(TFAIL,
							 "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d file_max 0x%x.",
							 me, CHUNK(chunk), val,
							 count, xfr, file_max);
						tst_resm(TINFO,
							 "\tTest[%d]: last_trunc = 0x%x.",
							 me, last_trunc);
						sync();
						ft_dumpiov(&r_iovec[i]);
						ft_dumpbits(bits,
							    (nchunks + 7) / 8);
						ft_orbits(hold_bits, bits,
							  (nchunks + 7) / 8);
						tst_resm(TINFO, "\tHold ");
						ft_dumpbits(hold_bits,
							    (nchunks + 7) / 8);
						tst_exit();
					}
				}
			}
			/*
			 * Writev it.
			 */
			if (lseek(fd, -xfr, 1) < 0) {
				tst_resm(TFAIL,
					 "\tTest[%d]: lseek(1) fail at %x, errno = %d.",
					 me, CHUNK(chunk), errno);
				tst_exit();
			}
			if ((xfr =
			     writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) {
				if (errno == ENOSPC) {
					tst_resm(TFAIL,
						 "\tTest[%d]: no space, exiting.",
						 me);
					fsync(fd);
					tst_exit();
				}
				tst_resm(TFAIL,
					 "\tTest[%d]: writev fail at %x xfr %d, errno = %d.",
					 me, CHUNK(chunk), xfr, errno);
				tst_exit();
			}
			if (CHUNK(chunk) + csize > file_max)
				file_max = CHUNK(chunk) + csize;
			/*
			 * If hit "misc" interval, do it.
			 */
			if (misc_intvl && --whenmisc <= 0) {
				ft_orbits(hold_bits, bits, (nchunks + 7) / 8);
				domisc(me, fd, bits);
				whenmisc = NEXTMISC;
			}
			if (count + collide > 2 * nchunks)
				break;
		}

		/*
		 * End of iteration, maybe before doing all chunks.
		 */

		fsync(fd);
		++misc_cnt[m_fsync];
		//tst_resm(TINFO, "\tTest{%d} val %d done, count = %d, collide = {%d}",
		//              me, val, count, collide);
		//for (i = 0; i < NMISC; i++)
		//      tst_resm(TINFO, "\t\tTest{%d}: {%d} %s's.", me, misc_cnt[i], m_str[i]);
		++val;
	}
}
Пример #6
0
/* XXX (garrcoop): should not be using libltp as it runs forked. */
static void dotest(int testers, int me, int fd)
{
	char *bits, *hold_bits, *buf, *val_buf, *zero_buf;
	char val;
	int count, collide, chunk, whenmisc, xfr, i;

	nchunks = max_size / csize;

	if ((bits = calloc((nchunks + 7) / 8, 1)) == 0) {
		tst_resm(TBROK,
			 "Test broken due to inability of malloc(bits).");
		tst_exit();
	}

	if ((hold_bits = calloc((nchunks + 7) / 8, 1)) == 0) {
		tst_resm(TBROK,
			 "Test broken due to inability of malloc(hold_bits).");
		tst_exit();
	}

	if ((buf = (calloc(csize, 1))) == 0) {
		tst_resm(TBROK, "Test broken due to inability of malloc(buf).");
		tst_exit();
	}

	if ((val_buf = (calloc(csize, 1))) == 0) {
		tst_resm(TBROK,
			 "Test broken due to inability of malloc(val_buf).");
		tst_exit();
	}

	if ((zero_buf = (calloc(csize, 1))) == 0) {
		tst_resm(TBROK,
			 "Test broken due to inability of malloc(zero_buf).");
		tst_exit();
	}

	/*
	 * No init sectors; allow file to be sparse.
	 */
	val = (64 / testers) * me + 1;

	/*
	 * For each iteration:
	 *      zap bits array
	 *      loop:
	 *              pick random chunk, read it.
	 *              if corresponding bit off {
	 *                      verify == 0. (sparse file)
	 *                      ++count;
	 *              } else
	 *                      verify == val.
	 *              write "val" on it.
	 *              repeat until count = nchunks.
	 *      ++val.
	 */
	srand(getpid());

	if (misc_intvl)
		whenmisc = NEXTMISC;

	while (iterations-- > 0) {
		for (i = 0; i < NMISC; i++)
			misc_cnt[i] = 0;
		ftruncate(fd, 0);
		file_max = 0;
		memset(bits, 0, (nchunks + 7) / 8);
		memset(hold_bits, 0, (nchunks + 7) / 8);
		memset(val_buf, val, csize);
		memset(zero_buf, 0, csize);
		count = 0;
		collide = 0;
		while (count < nchunks) {
			chunk = rand() % nchunks;
			/*
			 * Read it.
			 */
			if (lseek(fd, CHUNK(chunk), 0) < 0) {
				tst_resm(TFAIL,
					 "Test[%d]: lseek(0) fail at %x, errno = %d.",
					 me, CHUNK(chunk), errno);

				tst_exit();
			}
			if ((xfr = read(fd, buf, csize)) < 0) {
				tst_resm(TFAIL,
					 "Test[%d]: read fail at %x, errno = %d.",
					 me, CHUNK(chunk), errno);
				tst_exit();
			}
			/*
			 * If chunk beyond EOF just write on it.
			 * Else if bit off, haven't seen it yet.
			 * Else, have.  Verify values.
			 */
			if (CHUNK(chunk) >= file_max) {
				bits[chunk / 8] |= (1 << (chunk % 8));
				++count;
			} else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) {
				if (xfr != csize) {
					tst_resm(TFAIL,
						 "Test[%d]: xfr=%d != %d, zero read.",
						 me, xfr, csize);
					tst_exit();
				}
				if (memcmp(buf, zero_buf, csize)) {
					tst_resm(TFAIL,
						 "Test[%d] bad verify @ 0x%x for val %d "
						 "count %d xfr %d file_max 0x%x, should be %d.",
						 me, CHUNK(chunk), val, count,
						 xfr, file_max, zero_buf[0]);
					tst_resm(TFAIL,
						 "Test[%d]: last_trunc = 0x%x.",
						 me, last_trunc);
					sync();
					ft_dumpbuf(buf, csize);
					ft_dumpbits(bits, (nchunks + 7) / 8);
					ft_orbits(hold_bits, bits,
						  (nchunks + 7) / 8);
					tst_resm(TINFO, "Hold ");
					ft_dumpbits(hold_bits,
						    (nchunks + 7) / 8);
					tst_exit();
				}
				bits[chunk / 8] |= (1 << (chunk % 8));
				++count;
			} else {
				if (xfr != csize) {
					tst_resm(TFAIL,
						 "\tTest[%d]: xfr=%d != %d, val read.",
						 me, xfr, csize);
					tst_exit();
				}
				++collide;
				if (memcmp(buf, val_buf, csize)) {
					tst_resm(TFAIL,
						 "Test[%d] bad verify @ 0x%x for val %d "
						 "count %d xfr %d file_max 0x%x.",
						 me, CHUNK(chunk), val, count,
						 xfr, file_max);
					tst_resm(TFAIL,
						 "Test[%d]: last_trunc = 0x%x.",
						 me, last_trunc);
					sync();
					ft_dumpbuf(buf, csize);
					ft_dumpbits(bits, (nchunks + 7) / 8);
					ft_orbits(hold_bits, bits,
						  (nchunks + 7) / 8);
					tst_resm(TINFO, "Hold ");
					ft_dumpbits(hold_bits,
						    (nchunks + 7) / 8);
					tst_exit();
				}
			}
			/*
			 * Write it.
			 */
			if (lseek(fd, -xfr, 1) < 0) {
				tst_resm(TFAIL,
					 "Test[%d]: lseek(1) fail at %x, errno = %d.",
					 me, CHUNK(chunk), errno);
				tst_exit();
			}
			if ((xfr = write(fd, val_buf, csize)) < csize) {
				if (errno == ENOSPC) {
					tst_resm(TFAIL,
						 "Test[%d]: no space, exiting.",
						 me);
					fsync(fd);
					tst_exit();
				}
				tst_resm(TFAIL,
					 "Test[%d]: write fail at %x xfr %d, errno = %d.",
					 me, CHUNK(chunk), xfr, errno);
				tst_exit();
			}
			if (CHUNK(chunk) + csize > file_max)
				file_max = CHUNK(chunk) + csize;
			/*
			 * If hit "misc" interval, do it.
			 */
			if (misc_intvl && --whenmisc <= 0) {
				ft_orbits(hold_bits, bits, (nchunks + 7) / 8);
				domisc(me, fd, bits);
				whenmisc = NEXTMISC;
			}
			if (count + collide > 2 * nchunks)
				break;
		}

		/*
		 * End of iteration, maybe before doing all chunks.
		 */
		fsync(fd);
		++misc_cnt[m_fsync];
		//tst_resm(TINFO, "Test{%d} val %d done, count = %d, collide = {%d}",
		//              me, val, count, collide);
		//for (i = 0; i < NMISC; i++)
		//      tst_resm(TINFO, "Test{%d}: {%d} %s's.", me, misc_cnt[i], m_str[i]);
		++val;
	}
}
Пример #7
0
////////////////////////////////////////////////////////////////////////////
//
// LoadLIBShape()
//
int LoadLIBShape(char *SLIB_Filename, char *Filename,struct Shape *SHP)
{
	#define CHUNK(Name)	(*ptr == *Name) &&			\
								(*(ptr+1) == *(Name+1)) &&	\
								(*(ptr+2) == *(Name+2)) &&	\
								(*(ptr+3) == *(Name+3))


	int RT_CODE;
	FILE *fp;
	char CHUNK[5];
	char far *ptr;
	memptr IFFfile = NULL;
	unsigned long FileLen, size, ChunkLen;
	int loop;


	RT_CODE = 1;

	// Decompress to ram and return ptr to data and return len of data in
	//	passed variable...

	if (!LoadLIBFile(SLIB_Filename,Filename,&IFFfile))
		Quit("Error Loading Compressed lib shape!");

	// Evaluate the file
	//
	ptr = MK_FP(IFFfile,0);
	if (!CHUNK("FORM"))
		goto EXIT_FUNC;
	ptr += 4;

	FileLen = *(long far *)ptr;
	SwapLong((long far *)&FileLen);
	ptr += 4;

	if (!CHUNK("ILBM"))
		goto EXIT_FUNC;
	ptr += 4;

	FileLen += 4;
	while (FileLen)
	{
		ChunkLen = *(long far *)(ptr+4);
		SwapLong((long far *)&ChunkLen);
		ChunkLen = (ChunkLen+1) & 0xFFFFFFFE;

		if (CHUNK("BMHD"))
		{
			ptr += 8;
			SHP->bmHdr.w = ((struct BitMapHeader far *)ptr)->w;
			SHP->bmHdr.h = ((struct BitMapHeader far *)ptr)->h;
			SHP->bmHdr.x = ((struct BitMapHeader far *)ptr)->x;
			SHP->bmHdr.y = ((struct BitMapHeader far *)ptr)->y;
			SHP->bmHdr.d = ((struct BitMapHeader far *)ptr)->d;
			SHP->bmHdr.trans = ((struct BitMapHeader far *)ptr)->trans;
			SHP->bmHdr.comp = ((struct BitMapHeader far *)ptr)->comp;
			SHP->bmHdr.pad = ((struct BitMapHeader far *)ptr)->pad;
			SwapWord(&SHP->bmHdr.w);
			SwapWord(&SHP->bmHdr.h);
			SwapWord(&SHP->bmHdr.x);
			SwapWord(&SHP->bmHdr.y);
			ptr += ChunkLen;
		}
		else
		if (CHUNK("BODY"))
		{
			ptr += 4;
			size = *((long far *)ptr);
			ptr += 4;
			SwapLong((long far *)&size);
			SHP->BPR = (SHP->bmHdr.w+7) >> 3;
			MM_GetPtr(&SHP->Data,size);
			if (!SHP->Data)
				goto EXIT_FUNC;
			movedata(FP_SEG(ptr),FP_OFF(ptr),FP_SEG(SHP->Data),0,size);
			ptr += ChunkLen;

			break;
		}
		else
#define PATTERN(p,r)    {{p,sizeof(p)-1},{r,sizeof(r)-1},{{0},0}}
#define CHUNK(c)        {c,sizeof(c)-1}

AC_PATTERN_t patterns[] = {
    PATTERN("city", "[S1]"),    /* Replace "simplicity" with "[S1]" */
    PATTERN("the ", ""),        /* Replace "the " with an empty string */
    PATTERN("and", NULL),       /* Do not replace "and" */
    PATTERN("experience", "[S2]"),
    PATTERN("exp", "[S3]"),
    PATTERN("simplicity", "[S4]"),
    PATTERN("ease", "[S5]"),
};
#define PATTERN_COUNT (sizeof(patterns)/sizeof(AC_PATTERN_t))

AC_TEXT_t input_chunks[] = {
    CHUNK("experience "),
    CHUNK("the ease "),
    CHUNK("and simpli"),
    CHUNK("city of multifast"),
};
#define CHUNK_COUNT (sizeof(input_chunks)/sizeof(AC_TEXT_t))

/* Define a call-back function of type MF_REPLACE_CALBACK_f */
void listener (AC_TEXT_t *text, void *user);

/* The call-back function is called when:
 *      1. the replacement buffer is full
 *      2. the _rep_flush() is called
 *
 * Replacement buffer size is determined by the MF_REPLACEMENT_BUFFER_SIZE
 * macro
Пример #9
0
////////////////////////////////////////////////////////////////////////////
//
// LoadLIBShape()
//
id0_int_t LoadLIBShape(const id0_char_t *SLIB_Filename, const id0_char_t *Filename,struct Shape *SHP)
{
	#define CHUNK(Name)	(*ptr == *Name) &&			\
								(*(ptr+1) == *(Name+1)) &&	\
								(*(ptr+2) == *(Name+2)) &&	\
								(*(ptr+3) == *(Name+3))


	id0_int_t RT_CODE;
	//FILE *fp;
	//id0_char_t CHUNK[5];
	id0_char_t id0_far *ptr;
	memptr IFFfile = NULL;
	id0_unsigned_long_t FileLen, size, ChunkLen;
	//id0_int_t loop;


	RT_CODE = 1;

	// Decompress to ram and return ptr to data and return len of data in
	//	passed variable...

	if (!LoadLIBFile(SLIB_Filename,Filename,&IFFfile))
		Quit("Error Loading Compressed lib shape!");

	// Evaluate the file
	//
	ptr = (id0_char_t *)IFFfile;
	//ptr = MK_FP(IFFfile,0);
	if (!CHUNK("FORM"))
		goto EXIT_FUNC;
	ptr += 4;

    memcpy(&FileLen, ptr, sizeof(id0_unsigned_long_t));
    FileLen = BE_Cross_Swap32BE(FileLen);
	//FileLen = *(id0_long_t id0_far *)ptr;
	//SwapLong((id0_long_t id0_far *)&FileLen);
	ptr += 4;

	if (!CHUNK("ILBM"))
		goto EXIT_FUNC;
	ptr += 4;

	FileLen += 4;
	while (FileLen)
	{
        memcpy(&ChunkLen, (ptr+4), sizeof(id0_long_t));
        ChunkLen = BE_Cross_Swap32BE(ChunkLen);
		//ChunkLen = *(id0_long_t id0_far *)(ptr+4);
		//SwapLong((id0_long_t id0_far *)&ChunkLen);
		ChunkLen = (ChunkLen+1) & 0xFFFFFFFE;

		if (CHUNK("BMHD"))
		{
			ptr += 8;
			SHP->bmHdr.w = BE_Cross_Swap16BE(((struct BitMapHeader id0_far *)ptr)->w);
			SHP->bmHdr.h = BE_Cross_Swap16BE(((struct BitMapHeader id0_far *)ptr)->h);
			SHP->bmHdr.x = BE_Cross_Swap16BE(((struct BitMapHeader id0_far *)ptr)->x);
			SHP->bmHdr.y = BE_Cross_Swap16BE(((struct BitMapHeader id0_far *)ptr)->y);
#if 0
			SHP->bmHdr.w = ((struct BitMapHeader id0_far *)ptr)->w;
			SHP->bmHdr.h = ((struct BitMapHeader id0_far *)ptr)->h;
			SHP->bmHdr.x = ((struct BitMapHeader id0_far *)ptr)->x;
			SHP->bmHdr.y = ((struct BitMapHeader id0_far *)ptr)->y;
#endif
			SHP->bmHdr.d = ((struct BitMapHeader id0_far *)ptr)->d;
			SHP->bmHdr.trans = ((struct BitMapHeader id0_far *)ptr)->trans;
			SHP->bmHdr.comp = ((struct BitMapHeader id0_far *)ptr)->comp;
			SHP->bmHdr.pad = ((struct BitMapHeader id0_far *)ptr)->pad;
#if 0
			SwapWord(&SHP->bmHdr.w);
			SwapWord(&SHP->bmHdr.h);
			SwapWord(&SHP->bmHdr.x);
			SwapWord(&SHP->bmHdr.y);
#endif
			ptr += ChunkLen;
		}
		else
		if (CHUNK("BODY"))
		{
			ptr += 4;
            memcpy(&size, ptr, sizeof(id0_long_t));
            size = BE_Cross_Swap32BE(size);
			//size = *((id0_long_t id0_far *)ptr);
			ptr += 4;
			//SwapLong((id0_long_t id0_far *)&size);
			SHP->BPR = (SHP->bmHdr.w+7) >> 3;
			MM_GetPtr(&SHP->Data,size);
			if (!SHP->Data)
				goto EXIT_FUNC;
			//movedata(FP_SEG(ptr),FP_OFF(ptr),FP_SEG(SHP->Data),0,size);
			memcpy(SHP->Data,ptr,size);
			ptr += ChunkLen;

			break;
		}
		else