/*
 * Copyright (C) 2003 Luca Marzario
 * This is Free Software; see GPL.txt for details
 */

#ifndef CHECK_CONF_H
#define CHECK_CONF_H

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>

#include "test.h"

/* checking enviroment variables */
void inline check_env (char ** env, char * oceraroot)
{
	if (env != NULL) {
		int i, ok = 0;
		/* scan for enviroment variables  */
   		for ( i=0; env[i] != NULL; i++ ) {
      			if (!strncmp("OCERA_DIR", env[i], 9)) {
				strcpy(oceraroot, (env[i]+10));
				ok = 1;
				break;
      			}
   		}
		if (!ok) {
			char component_dir[100];
   			for (i=0; env[i] != NULL; i++ ) {
      				if ( !strncmp("LTPROOT", env[i], 7)) {
					sprintf(oceraroot, "%s/..", (env[i]+8));
					sprintf(component_dir, "%s/components", oceraroot);
					if (opendir(component_dir) != NULL)
						ok = 1;
					break;
      				}
   			}
			if (!ok) {
				tst_brkm(TBROK, NULL, "[CONF] OCERAROOT & LTPROOT not defined\n");
				tst_exit();
			}
		}
		printf("oceraroot: %s\n", oceraroot);
	}
}

/* checking kernel configuration */
void inline check_kernel_conf(char * ocera_dir, char * conf_option)
{
	char cmd[100];
	sprintf(cmd, "$LTPROOT/tools/check_config %s/kernel/linux/.config %s", ocera_dir, conf_option);
	printf("command: %s\n", cmd);
	if (system (cmd)) {
		tst_brkm(TBROK, NULL, "[CONF] Kernel configuration problem"); 
		tst_exit();
	}
}
#endif

