Exemple #1
0
void test_create_file_at()
{
  char *file = alloc_filename("file");
  char *hardlink = alloc_filename("hardlink");
  char *hardlink2 = alloc_filename("hardlink2");
  int dir_fd = get_dir_fd(".");
  struct stat st;
  int fd = openat(dir_fd, file, O_CREAT | O_WRONLY | O_EXCL, 0777);
  t_check(fd >= 0);
  t_check_zero(fstat(fd, &st));
  t_check_zero(close(fd));

  t_check_zero(fstatat(dir_fd, file, &st, 0));
  t_check_zero(faccessat(dir_fd, file, R_OK | W_OK, 0));
  t_check_zero(fchmodat(dir_fd, file, 0777, 0));
  t_check_zero(fchownat(dir_fd, file, -1, -1, 0));
  struct timeval times[2] = { { 123, 321 }, { 456, 654 } };
  t_check_zero(futimesat(dir_fd, file, times));

  t_check_zero(linkat(dir_fd, file, dir_fd, hardlink, 0));
  t_check_zero(renameat(dir_fd, hardlink, dir_fd, hardlink2));
  t_check_zero(unlinkat(dir_fd, hardlink2, 0));
  t_check_zero(unlinkat(dir_fd, file, 0));
  close(dir_fd);
  free(file);
  free(hardlink);
  free(hardlink2);
}
Exemple #2
0
void test_create_file()
{
  char *file = alloc_filename("file");
  char *hardlink = alloc_filename("hardlink");
  char *hardlink2 = alloc_filename("hardlink2");
  struct stat st;
  int fd = open(file, O_CREAT | O_WRONLY | O_EXCL, 0666);
  t_check(fd >= 0);
  t_check_zero(fstat(fd, &st));
  t_check_zero(close(fd));

  t_check_zero(stat(file, &st));
  t_check_zero(access(file, R_OK | W_OK));
  t_check_zero(chmod(file, 0777));
  t_check_zero(chown(file, -1, -1));
  struct timeval times[2] = { { 123, 321 }, { 456, 654 } };
  t_check_zero(utimes(file, times));

  t_check_zero(link(file, hardlink));
  t_check_zero(rename(hardlink, hardlink2));
  t_check_zero(unlink(hardlink2));
  t_check_zero(unlink(file));
  free(file);
  free(hardlink);
  free(hardlink2);
}
Exemple #3
0
void test_create_dir()
{
  char *dir = alloc_filename("dir");
  t_check_zero(mkdir(dir, 0777));
  t_check_zero(rmdir(dir));
  free(dir);
}
Exemple #4
0
static void file_error( const char *msg, fio *f, bool delete_f = false ) {
	gc_exit_blocking();
	value a = alloc_array(2);
	val_array_set_i(a,0,alloc_string(msg));
	val_array_set_i(a,1,alloc_filename(f->name.c_str()));
	if (delete_f)
		delete f;
	val_throw(a);
}
Exemple #5
0
void test_create_dir_at()
{
  char *dir = alloc_filename("dir");
  int dir_fd = get_dir_fd(".");
  t_check_zero(mkdirat(dir_fd, dir, 0777));
  t_check_zero(unlinkat(dir_fd, dir, AT_REMOVEDIR));
  close(dir_fd);
  free(dir);
}
Exemple #6
0
void test_bind()
{
  char *socket_filename = alloc_filename("socket");
  int fd;
  struct sockaddr_un addr;

  fd = socket(PF_UNIX, SOCK_STREAM, 0);
  t_check(fd >= 0);
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, socket_filename);
  t_check_zero(bind(fd, (struct sockaddr *) &addr,
                    sizeof(struct sockaddr_un)));
  t_check_zero(close(fd));
  t_check_zero(unlink(socket_filename));
  free(socket_filename);
}
Exemple #7
0
void test_create_symlink()
{
  char *symlink_filename = alloc_filename("symlink");
  const char *dest_path = "dest_path";
  t_check_zero(symlink(dest_path, symlink_filename));

  char buf[100];
  int got;
  got = readlink(symlink_filename, buf, sizeof(buf));
  t_check(got >= 0);
  assert(got == strlen(dest_path));
  buf[got] = 0;
  assert(strcmp(buf, dest_path) == 0);

  t_check_zero(unlink(symlink_filename));
  free(symlink_filename);
}
static void epm_error_saving_file(struct epm_action *action, int error,
				  struct task_struct *task, struct file *file,
				  int index)
{
	char *buffer, *filename;
	filename = alloc_filename(file, &buffer);
	if (!IS_ERR(filename)) {
		epm_error(action, error, task,
			  "Fail to save information about file %s "
			  "as fd %d", filename, index);
		free_filename(buffer);
	} else {
		epm_error(action, error, task,
			  "Fail to save information about fd %d",
			  index);
	}
}
Exemple #9
0
static int cr_export_now_file(struct epm_action *action, ghost_t *ghost,
			      struct task_struct *task,
			      union export_args *args)
{
	int r, supported;

	supported = can_checkpoint_file(args->file_args.file);

	r = ghost_write(ghost, &supported, sizeof(supported));
	if (r)
		goto error;

	if (supported)
		r = regular_file_export(action, ghost, task,
					args->file_args.index,
					args->file_args.file);

error:
	if (r) {
		char *buffer, *filename;
		filename = alloc_filename(args->file_args.file, &buffer);
		if (!IS_ERR(filename)) {
			ckpt_err(action, r,
				 "Fail to save information needed to reopen "
				 "file %s as fd %d of process %d (%s)",
				 filename, args->file_args.index,
				 task_pid_knr(task), task->comm);
			free_filename(buffer);
		} else {
			ckpt_err(action, r,
				 "Fail to save information needed to reopen "
				 "fd %d of process %d (%s)",
				 args->file_args.index,
				 task_pid_knr(task), task->comm);
		}
	}

	return r;
}
Exemple #10
0
/**
	file_name : 'file -> string
	<doc>Return the name of the file which was opened</doc>
**/
static value file_name( value o ) {
	val_check_kind(o,k_file);
	return alloc_filename(val_file(o)->name.c_str());
}
Exemple #11
0
static int generate_png_diff(const summary_file *curfile, const char *destdir, const char *destname)
{
	const char *dstfilename = alloc_filename(destdir, destname);
	bitmap_t *bitmaps[MAX_COMPARES] = { NULL };
	bitmap_t *finalbitmap = NULL;
	int width, height, maxwidth;
	int bitmapcount = 0;
	int listnum, bmnum;
	core_file *file = NULL;
	char srcimgname[50];
	file_error filerr;
	png_error pngerr;
	int error = -1;
	int starty;

	/* generate the common source filename */
	sprintf(srcimgname, "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name);

	/* open and load all unique bitmaps */
	for (listnum = 0; listnum < list_count; listnum++)
		if (curfile->matchbitmap[listnum] == listnum)
		{
			const char *filename = alloc_filename(lists[listnum].dir, srcimgname);

			/* open the source image */
			filerr = core_fopen(filename, OPEN_FLAG_READ, &file);
			free((void *)filename);
			if (filerr != FILERR_NONE)
				goto error;

			/* load the source image */
			pngerr = png_read_bitmap(file, &bitmaps[bitmapcount++]);
			core_fclose(file);
			if (pngerr != FILERR_NONE)
				goto error;
		}

	/* if there's only one unique bitmap, skip it */
	if (bitmapcount <= 1)
		goto error;

	/* determine the size of the final bitmap */
	height = width = 0;
	maxwidth = bitmaps[0]->width;
	for (bmnum = 1; bmnum < bitmapcount; bmnum++)
	{
		int curwidth;

		/* determine the maximal width */
		maxwidth = MAX(maxwidth, bitmaps[bmnum]->width);
		curwidth = bitmaps[0]->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth;
		width = MAX(width, curwidth);

		/* add to the height */
		height += MAX(bitmaps[0]->height, bitmaps[bmnum]->height);
		if (bmnum != 1)
			height += BITMAP_SPACE;
	}

	/* allocate the final bitmap */
	finalbitmap = bitmap_alloc(width, height, BITMAP_FORMAT_ARGB32);
	if (finalbitmap == NULL)
		goto error;

	/* now copy and compare each set of bitmaps */
	starty = 0;
	for (bmnum = 1; bmnum < bitmapcount; bmnum++)
	{
		bitmap_t *bitmap1 = bitmaps[0];
		bitmap_t *bitmap2 = bitmaps[bmnum];
		int curheight = MAX(bitmap1->height, bitmap2->height);
		int x, y;

		/* iterate over rows in these bitmaps */
		for (y = 0; y < curheight; y++)
		{
			UINT32 *src1 = (y < bitmap1->height) ? BITMAP_ADDR32(bitmap1, y, 0) : NULL;
			UINT32 *src2 = (y < bitmap2->height) ? BITMAP_ADDR32(bitmap2, y, 0) : NULL;
			UINT32 *dst1 = BITMAP_ADDR32(finalbitmap, starty + y, 0);
			UINT32 *dst2 = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE);
			UINT32 *dstdiff = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE + maxwidth + BITMAP_SPACE);

			/* now iterate over columns */
			for (x = 0; x < maxwidth; x++)
			{
				int pix1 = -1, pix2 = -2;

				if (src1 != NULL && x < bitmap1->width)
					pix1 = dst1[x] = src1[x];
				if (src2 != NULL && x < bitmap2->width)
					pix2 = dst2[x] = src2[x];
				dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000;
			}
		}

		/* update the starting Y position */
		starty += BITMAP_SPACE + MAX(bitmap1->height, bitmap2->height);
	}

	/* write the final PNG */
	filerr = core_fopen(dstfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
	if (filerr != FILERR_NONE)
		goto error;
	pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL);
	core_fclose(file);
	if (pngerr != FILERR_NONE)
		goto error;

	/* if we get here, we are error free */
	error = 0;

error:
	if (dstfilename != NULL)
		free((void *)dstfilename);
	if (finalbitmap != NULL)
		bitmap_free(finalbitmap);
	for (bmnum = 0; bmnum < bitmapcount; bmnum++)
		if (bitmaps[bmnum] != NULL)
			bitmap_free(bitmaps[bmnum]);
	if (error)
		osd_rmfile(dstfilename);
	return error;
}
Exemple #12
0
static int compare_screenshots(summary_file *curfile)
{
	bitmap_t *bitmaps[MAX_COMPARES];
	int unique[MAX_COMPARES];
	int numunique = 0;
	int listnum;

	/* iterate over all files and load their bitmaps */
	for (listnum = 0; listnum < list_count; listnum++)
	{
		bitmaps[listnum] = NULL;
		if (curfile->status[listnum] == STATUS_SUCCESS)
		{
			file_error filerr;
			const char *fullname;
			char imgname[100];
			core_file *file;

			/* get the filename for the image */
			sprintf(imgname, "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name);
			fullname = alloc_filename(lists[listnum].dir, imgname);

			/* open the file */
			filerr = core_fopen(fullname, OPEN_FLAG_READ, &file);
			free((void *)fullname);

			/* if that failed, look in the old location */
			if (filerr != FILERR_NONE)
			{
				/* get the filename for the image */
				sprintf(imgname, "snap" PATH_SEPARATOR "_%s.png", curfile->name);
				fullname = alloc_filename(lists[listnum].dir, imgname);

				/* open the file */
				filerr = core_fopen(fullname, OPEN_FLAG_READ, &file);
				free((void *)fullname);
			}

			/* if that worked, load the file */
			if (filerr == FILERR_NONE)
			{
				png_read_bitmap(file, &bitmaps[listnum]);
				core_fclose(file);
			}
		}
	}

	/* now find all the different bitmap types */
	for (listnum = 0; listnum < list_count; listnum++)
	{
		curfile->matchbitmap[listnum] = 0xff;
		if (bitmaps[listnum] != NULL)
		{
			bitmap_t *this_bitmap = bitmaps[listnum];
			int compnum;

			/* compare against all unique bitmaps */
			for (compnum = 0; compnum < numunique; compnum++)
			{
				bitmap_t *base_bitmap = bitmaps[unique[compnum]];
				int bitmaps_differ;
				int x, y;

				/* if the sizes are different, we differ; otherwise start off assuming we are the same */
				bitmaps_differ = (this_bitmap->width != base_bitmap->width || this_bitmap->height != base_bitmap->height);

				/* compare scanline by scanline */
				for (y = 0; y < this_bitmap->height && !bitmaps_differ; y++)
				{
					UINT32 *base = BITMAP_ADDR32(base_bitmap, y, 0);
					UINT32 *curr = BITMAP_ADDR32(this_bitmap, y, 0);

					/* scan the scanline */
					for (x = 0; x < this_bitmap->width; x++)
						if (*base++ != *curr++)
							break;
					bitmaps_differ = (x != this_bitmap->width);
				}

				/* if we matched, remember which listnum index we matched, and stop */
				if (!bitmaps_differ)
				{
					curfile->matchbitmap[listnum] = unique[compnum];
					break;
				}

				/* if different from the first unique entry, adjust the status */
				if (bitmaps_differ && compnum == 0)
					curfile->status[listnum] = STATUS_SUCCESS_DIFFERENT;
			}

			/* if we're unique, add ourselves to the list */
			if (compnum >= numunique)
			{
				unique[numunique++] = listnum;
				curfile->matchbitmap[listnum] = listnum;
				continue;
			}
		}
	}

	/* free the bitmaps */
	for (listnum = 0; listnum < list_count; listnum++)
		if (bitmaps[listnum] != NULL)
			bitmap_free(bitmaps[listnum]);

	/* if all screenshots matched, we're good */
	if (numunique == 1)
		return BUCKET_GOOD;

	/* if the last screenshot matched the first unique one, we're good but changed */
	if (curfile->matchbitmap[listnum - 1] == unique[0])
		return BUCKET_GOOD_BUT_CHANGED_SCREENSHOTS;

	/* otherwise we're just changed */
	return BUCKET_CHANGED;
}
Exemple #13
0
static void output_report(const char *dirname, summary_file *filelist)
{
	summary_file *buckethead[BUCKET_COUNT], **buckettailptr[BUCKET_COUNT];
	summary_file *curfile;
	const char *indexname;
	int listnum, bucknum;
	FILE *indexfile;
	int count = 0, total;

	/* initialize the lists */
	for (bucknum = 0; bucknum < BUCKET_COUNT; bucknum++)
	{
		buckethead[bucknum] = NULL;
		buckettailptr[bucknum] = &buckethead[bucknum];
	}

	/* compute the total number of files */
	total = 0;
	for (curfile = filelist; curfile != NULL; curfile = curfile->next)
		total++;

	/* first bucketize the games */
	for (curfile = filelist; curfile != NULL; curfile = curfile->next)
	{
		int statcount[STATUS_COUNT] = { 0 };
		int bucket = BUCKET_UNKNOWN;
		int unique_codes = 0;
		int first_valid;

		/* print status */
		if (++count % 100 == 0)
			fprintf(stderr, "Processing file %d/%d\n", count, total);

		/* find the first valid entry */
		for (first_valid = 0; curfile->status[first_valid] == STATUS_NOT_PRESENT; first_valid++) ;

		/* do we need to output anything? */
		for (listnum = first_valid; listnum < list_count; listnum++)
			if (statcount[curfile->status[listnum]]++ == 0)
				unique_codes++;

		/* were we consistent? */
		if (unique_codes == 1)
		{
			/* were we consistently ok? */
			if (curfile->status[first_valid] == STATUS_SUCCESS)
				bucket = compare_screenshots(curfile);

			/* must have been consistently erroring */
			else
				bucket = BUCKET_CONSISTENT_ERROR;
		}

		/* ok, we're not consistent; could be a number of things */
		else
		{
			/* were we ok at the start and end but not in the middle? */
			if (curfile->status[first_valid] == STATUS_SUCCESS && curfile->status[list_count - 1] == STATUS_SUCCESS)
				bucket = BUCKET_GOOD_BUT_CHANGED;

			/* did we go from good to bad? */
			else if (curfile->status[first_valid] == STATUS_SUCCESS)
				bucket = BUCKET_REGRESSED;

			/* did we go from bad to good? */
			else if (curfile->status[list_count - 1] == STATUS_SUCCESS)
				bucket = BUCKET_IMPROVED;

			/* must have had multiple errors */
			else
				bucket = BUCKET_MULTI_ERROR;
		}

		/* add us to the appropriate list */
		*buckettailptr[bucket] = curfile;
		buckettailptr[bucket] = &curfile->next;
	}

	/* terminate all the lists */
	for (bucknum = 0; bucknum < BUCKET_COUNT; bucknum++)
		*buckettailptr[bucknum] = NULL;

	/* output header */
	indexname = alloc_filename(dirname, "index.html");
	indexfile = create_file_and_output_header(indexname, "MAME&trade; Regressions", NULL);
	free((void *)indexname);
	if (indexfile == NULL)
	{
		fprintf(stderr, "Error creating file '%s'\n", indexname);
		return;
	}

	/* iterate over buckets and output them */
	for (bucknum = 0; bucknum < ARRAY_LENGTH(bucket_output_order); bucknum++)
	{
		int curbucket = bucket_output_order[bucknum];

		if (buckethead[curbucket] != NULL)
		{
			fprintf(stderr, "Outputting bucket: %s\n", bucket_name[curbucket]);
			append_driver_list_table(bucket_name[curbucket], dirname, indexfile, buckethead[curbucket]);
		}
	}

	/* output footer */
	output_footer_and_close_file(indexfile);
}
Exemple #14
0
static void create_linked_file(const char *dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile)
{
	const char *linkname;
	char filename[100];
	char title[100];
	FILE *linkfile;
	int listnum;

	/* create the filename */
	sprintf(filename, "%s.html", curfile->name);

	/* output header */
	sprintf(title, "%s Regressions", curfile->name);
	linkname = alloc_filename(dirname, filename);
	linkfile = create_file_and_output_header(linkname, title, NULL);
	free((void *)linkname);
	if (linkfile == NULL)
	{
		fprintf(stderr, "Error creating file '%s'\n", filename);
		return;
	}

	/* link to the previous/next entries */
	fprintf(linkfile, "\t<p>\n");
	fprintf(linkfile, "\t<table width=\"100%%\">\n");
	fprintf(linkfile, "\t\t<td align=\"left\" width=\"40%%\" style=\"border:none\">");
	if (prevfile != NULL)
		fprintf(linkfile, "<a href=\"%s.html\"><< %s (%s)</a>", prevfile->name, prevfile->name, prevfile->source);
	fprintf(linkfile, "</td>\n");
	fprintf(linkfile, "\t\t<td align=\"center\" width=\"20%%\" style=\"border:none\"><a href=\"index.html\">Home</a></td>\n");
	fprintf(linkfile, "\t\t<td align=\"right\" width=\"40%%\" style=\"border:none\">");
	if (nextfile != NULL)
		fprintf(linkfile, "<a href=\"%s.html\">%s (%s) >></a>", nextfile->name, nextfile->name, nextfile->source);
	fprintf(linkfile, "</td>\n");
	fprintf(linkfile, "\t</table>\n");
	fprintf(linkfile, "\t</p>\n");

	/* output data for each one */
	for (listnum = 0; listnum < list_count; listnum++)
	{
		int imageindex = -1;

		/* generate the HTML */
		fprintf(linkfile, "\n\t<h2>%s</h2>\n", lists[listnum].version);
		fprintf(linkfile, "\t<p>\n");
		fprintf(linkfile, "\t<b>Status:</b> %s\n", status_text[curfile->status[listnum]]);
		if (pngfile != NULL)
			imageindex = get_unique_index(curfile, listnum);
		if (imageindex != -1)
			fprintf(linkfile, " [%d]", imageindex);
		fprintf(linkfile, "\t</p>\n");
		if (curfile->text[listnum] != NULL)
		{
			fprintf(linkfile, "\t<p>\n");
			fprintf(linkfile, "\t<b>Errors:</b>\n");
			fprintf(linkfile, "\t<pre>%s</pre>\n", curfile->text[listnum]);
			fprintf(linkfile, "\t</p>\n");
		}
	}

	/* output link to the image */
	if (pngfile != NULL)
	{
		fprintf(linkfile, "\n\t<h2>Screenshot Comparisons</h2>\n");
		fprintf(linkfile, "\t<p>\n");
		fprintf(linkfile, "\t<img src=\"%s\" />\n", pngfile);
		fprintf(linkfile, "\t</p>\n");
	}

	/* output footer */
	output_footer_and_close_file(linkfile);
}