Beispiel #1
0
/*
 * cat_file() - Print the contents of a file to standard out.
 */
void tst_cat_file(const char *filename)
{
	FILE *fp;
	int b_read, b_written;
	char buffer[BUFSIZ];

#if DEBUG
	printf("IN cat_file\n");
	fflush(stdout);
#endif

	/*
	 * Unless T_out has already been set by tst_environ(), make tst_res()
	 * output go to standard output.
	 */
	if (T_out == NULL)
		T_out = stdout;

	if ((fp = fopen(filename, "r")) == NULL) {
		sprintf(Warn_mesg,
			"tst_res(): fopen(%s, \"r\") failed; errno = %d: %s",
			filename, errno, strerror(errno));
		tst_print(TCID, 0, TWARN, Warn_mesg);
		return;
	}

	errno = 0;

	while ((b_read = fread(buffer, 1, BUFSIZ, fp)) != 0) {
		if ((b_written = fwrite(buffer, 1, b_read, T_out)) != b_read) {
			sprintf(Warn_mesg,
				"tst_res(): While trying to cat \"%s\", "
				"fwrite() wrote only %d of %d bytes",
				filename, b_written, b_read);
			tst_print(TCID, 0, TWARN, Warn_mesg);
			break;
		}
	}

	if (!feof(fp)) {
		sprintf(Warn_mesg,
			"tst_res(): While trying to cat \"%s\", fread() "
			"failed, errno = %d: %s",
			filename, errno, strerror(errno));
		tst_print(TCID, 0, TWARN, Warn_mesg);
	}

	if (fclose(fp) != 0) {
		sprintf(Warn_mesg,
			"tst_res(): While trying to cat \"%s\", fclose() "
			"failed, errno = %d: %s",
			filename, errno, strerror(errno));
		tst_print(TCID, 0, TWARN, Warn_mesg);
	}
}
Beispiel #2
0
static void tst_res__(const char *file, const int lineno, int ttype,
                      const char *arg_fmt, ...)
{
	pthread_mutex_lock(&tmutex);

	char tmesg[USERMESG];
	int len = 0;
	int ttype_result = TTYPE_RESULT(ttype);

	if (file && (ttype_result != TPASS && ttype_result != TINFO))
		len = sprintf(tmesg, "%s:%d: ", file, lineno);
	EXPAND_VAR_ARGS(tmesg + len, arg_fmt, USERMESG - len);

	/*
	 * Save the test result type by ORing ttype into the current exit
	 * value (used by tst_exit()).
	 */
	T_exitval |= ttype_result;

	if (ttype_result == TPASS)
		passed_cnt++;

	check_env();

	/*
	 * Set the test case number and print the results, depending on the
	 * display type.
	 */
	if (ttype_result == TWARN || ttype_result == TINFO) {
		tst_print(TCID, 0, ttype, tmesg);
	} else {
		if (tst_count < 0)
			tst_print(TCID, 0, TWARN,
				  "tst_res(): tst_count < 0 is not valid");

		/*
		 * Process each display type.
		 */
		switch (T_mode) {
		case DISCARD:
			break;
		case NOPASS:	/* filtered by tst_print() */
			tst_condense(tst_count + 1, ttype, tmesg);
			break;
		default:	/* VERBOSE */
			tst_print(TCID, tst_count + 1, ttype, tmesg);
			break;
		}

		tst_count++;
	}

	pthread_mutex_unlock(&tmutex);
}
Beispiel #3
0
/*
 * tst_condense() - Handle test cases in NOPASS mode (i.e.
 *                  buffer the current result and print the last result
 *                  if different than the current).  If a file was
 *                  specified, print the current result and do not
 *                  buffer it.
 */
static void tst_condense(int tnum, int ttype, const char *tmesg)
{
	const char *file;
	int ttype_result = TTYPE_RESULT(ttype);

#if DEBUG
	printf("IN tst_condense: tcid = %s, tnum = %d, ttype = %d, "
	       "tmesg = %s\n", TCID, tnum, ttype, tmesg);
	fflush(stdout);
#endif

	/*
	 * If this result is the same as the previous result, return.
	 */
	if (Buffered == TRUE) {
		if (strcmp(Last_tcid, TCID) == 0 && Last_type == ttype_result &&
		    strcmp(Last_mesg, tmesg) == 0 && File == NULL)
			return;

		/*
		 * This result is different from the previous result.  First,
		 * print the previous result.
		 */
		file = File;
		File = NULL;
		tst_print(Last_tcid, Last_num, Last_type, Last_mesg);
		free(Last_tcid);
		free(Last_mesg);
		File = file;
	}

	/*
	 * If a file was specified, print the current result since we have no
	 * way of retaining the file contents for comparing with future
	 * results.  Otherwise, buffer the current result info for next time.
	 */
	if (File != NULL) {
		tst_print(TCID, tnum, ttype, tmesg);
		Buffered = FALSE;
	} else {
		Last_tcid = malloc(strlen(TCID) + 1);
		strcpy(Last_tcid, TCID);
		Last_num = tnum;
		Last_type = ttype_result;
		Last_mesg = malloc(strlen(tmesg) + 1);
		strcpy(Last_mesg, tmesg);
		Buffered = TRUE;
	}
}
Beispiel #4
0
static void tst_condense(int tnum, int ttype, const char *tmesg)
{
	int ttype_result = TTYPE_RESULT(ttype);

	/*
	 * If this result is the same as the previous result, return.
	 */
	if (Buffered == TRUE) {
		if (strcmp(Last_tcid, TCID) == 0 && Last_type == ttype_result &&
		    strcmp(Last_mesg, tmesg) == 0)
			return;

		/*
		 * This result is different from the previous result.  First,
		 * print the previous result.
		 */
		tst_print(Last_tcid, Last_num, Last_type, Last_mesg);
		free(Last_tcid);
		free(Last_mesg);
	}

	/*
	 * If a file was specified, print the current result since we have no
	 * way of retaining the file contents for comparing with future
	 * results.  Otherwise, buffer the current result info for next time.
	 */
	Last_tcid = malloc(strlen(TCID) + 1);
	strcpy(Last_tcid, TCID);
	Last_num = tnum;
	Last_type = ttype_result;
	Last_mesg = malloc(strlen(tmesg) + 1);
	strcpy(Last_mesg, tmesg);
	Buffered = TRUE;
}
Beispiel #5
0
static void tst_brk__(const char *file, const int lineno, int ttype,
                      const char *fname, void (*func)(void),
                      const char *arg_fmt, ...)
{
	pthread_mutex_lock(&tmutex);

	char tmesg[USERMESG];
	int ttype_result = TTYPE_RESULT(ttype);

#if DEBUG
	printf("IN tst_brk__\n");
	fflush(stdout);
	fflush(stdout);
#endif

	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);

	/*
	 * Only FAIL, BROK, CONF, and RETR are supported by tst_brk().
	 */
	if (ttype_result != TFAIL && ttype_result != TBROK &&
	    ttype_result != TCONF) {
		sprintf(Warn_mesg, "%s: Invalid Type: %d. Using TBROK",
			__func__, ttype_result);
		tst_print(TCID, 0, TWARN, Warn_mesg);
		/* Keep TERRNO, TTERRNO, etc. */
		ttype = (ttype & ~ttype_result) | TBROK;
	}

	tst_res__(file, lineno, ttype, fname, "%s", tmesg);
	if (tst_brk_entered == 0) {
		if (ttype_result == TCONF) {
			tst_res__(file, lineno, ttype, NULL,
				"Remaining cases not appropriate for "
				"configuration");
		} else if (ttype_result == TBROK) {
			tst_res__(file, lineno, TBROK, NULL,
				 "Remaining cases broken");
		}
	}

	/*
	 * If no cleanup function was specified, just return to the caller.
	 * Otherwise call the specified function.
	 */
	if (func != NULL) {
		tst_brk_entered++;
		(*func) ();
		tst_brk_entered--;
	}
	if (tst_brk_entered == 0)
		tst_exit();

	pthread_mutex_unlock(&tmutex);
}
Beispiel #6
0
void tst_flush(void)
{
	pthread_mutex_lock(&tmutex);

	/*
	 * Print out last line if in NOPASS mode.
	 */
	if (Buffered == TRUE && T_mode == NOPASS) {
		tst_print(Last_tcid, Last_num, Last_type, Last_mesg);
		Buffered = FALSE;
	}

	fflush(stdout);

	pthread_mutex_unlock(&tmutex);
}
Beispiel #7
0
int 
main() {
	int ch;
	dlq_hdl_t *q_hdl;

	q_hdl = dlq_create(5);
	if(q_hdl == NULL) {
#ifdef DEBUG
		info("Queue creation failed.\n");
#endif
		return 1;
	}
	
	do {
		printf("1 - Enqueue data.\n");
		printf("2 - Dequeue data.\n");
		printf("3 - Print queue.\n");	
		printf("4 - Print queue size.\n");	
		printf("5 - Bringfront.\n");	
		scanf("%d", &ch);

		switch(ch) {
		case 1:
			tst_enqueue(q_hdl);
			break;
		case 2:
			tst_dequeue(q_hdl);
			break;
		case 3:
			tst_print(q_hdl);
			break;
		case 4:
			tst_size(q_hdl);
			break;
		case 5:
			tst_bringfront(q_hdl);
			break;
		default:
			dlq_destroy(q_hdl);
			q_hdl = NULL;
			return 0;
			break;
		}
	} while (ch > 0 && ch < 6);

	return 1;
}
Beispiel #8
0
static void tst_res__(const char *file, const int lineno, int ttype,
	const char *fname, const char *arg_fmt, ...)
{
	pthread_mutex_lock(&tmutex);

	char tmesg[USERMESG];
	int len = 0;
	int ttype_result = TTYPE_RESULT(ttype);

#if DEBUG
	printf("IN tst_res__; tst_count = %d\n", tst_count);
	fflush(stdout);
#endif

	if (file && (ttype_result != TPASS && ttype_result != TINFO))
		len = sprintf(tmesg, "%s:%d: ", file, lineno);
	EXPAND_VAR_ARGS(tmesg + len, arg_fmt, USERMESG - len);

	/*
	 * Save the test result type by ORing ttype into the current exit
	 * value (used by tst_exit()).
	 */
	T_exitval |= ttype_result;

	/*
	 * Unless T_out has already been set by tst_environ(), make tst_res()
	 * output go to standard output.
	 */
	if (T_out == NULL)
		T_out = stdout;

	/*
	 * Check TOUTPUT environment variable (if first time) and set T_mode
	 * flag.
	 */
	check_env();

	if (fname != NULL && access(fname, F_OK) == 0)
		File = fname;

	/*
	 * Set the test case number and print the results, depending on the
	 * display type.
	 */
	if (ttype_result == TWARN || ttype_result == TINFO) {
		tst_print(TCID, 0, ttype, tmesg);
	} else {
		if (tst_count < 0)
			tst_print(TCID, 0, TWARN,
				  "tst_res(): tst_count < 0 is not valid");

		/*
		 * Process each display type.
		 */
		switch (T_mode) {
		case DISCARD:
			break;
		case NOPASS:	/* filtered by tst_print() */
			tst_condense(tst_count + 1, ttype, tmesg);
			break;
		default:	/* VERBOSE */
			tst_print(TCID, tst_count + 1, ttype, tmesg);
			break;
		}

		tst_count++;
	}

	pthread_mutex_unlock(&tmutex);
}