Esempio n. 1
0
int processWait()
{
  logTest("processWait", "Going to wait for the running processes");

  for (int i = 0; i < DEFAULT_PROCESS_ENTRIES; i++)
  {
    if (processes[i] != NULL)
    {
      logTest("processWait", "Waiting for the process with pid %d",
                  processes[i] -> getPid());

      for (;;)
      {
        if (processes[i] -> wait() == 1)
        {
          delete processes[i];

          processes[i] = NULL;

          break;
        }
      }
    }
  }

  logTest("processWait", "All children processes exited");

  return 1;
}
Esempio n. 2
0
int processCheck()
{
  logTest("processCheck", "Going to check the exited processes");

  for (int i = 0; i < DEFAULT_PROCESS_ENTRIES; i++)
  {
    if (processes[i] != NULL)
    {
      if (processes[i] -> isRunning() == 0)
      {
        logTest("processCheck", "Process with pid %d has died",
                    processes[i] -> getPid());

        delete processes[i];

        processes[i] = NULL;
      }
      else
      {
        logTest("processCheck", "Process with pid %d is running",
                    processes[i] -> getPid());
      }
    }
  }

  return 1;
}
Esempio n. 3
0
int Process::parseStatus(int result, int status)
{
  logTrace("Process::parseStatus");

  if (result > 0)
  {
    if (WIFSTOPPED(status))
    {
      logTest("Process::parseStatus", "Child %d was stopped "
                  "with signal %d", pid_, (WSTOPSIG(status)));
    }
    else
    {
      #ifdef TEST

      if (WIFEXITED(status))
      {
        logTest("Process::parseStatus", "Child %d exited "
                    "with status %d", pid_, (WEXITSTATUS(status)));
      }
      else if (WIFSIGNALED(status))
      {
        logTest("Process::parseStatus", "Child %d died "
                    "because of signal %d", pid_, (WTERMSIG(status)));
      }

      #endif

      status_ = status;

      return 1;
    }
  }
  else if (result < 0)
  {
    if (EGET() == ECHILD)
    {
      //
      // The process died but we missed to
      // call the waitpid() at the time.
      //

      logWarning("Process::parseStatus::waitpid", EGET());

      return 1;
    }

    logError("Process::parseStatus::waitpid", EGET());

    return -1;
  }

  return 0;
}
Esempio n. 4
0
/* *********************************** */
int ProSLIC_testInBattery(proslicChanType *pProslic, proslicTestInObjType *pTstin)
{
proslicMonitorType monitor;

	/* Valid device check */
	if(TSTIN_INVALID_PART_NUM)
	{
		return RC_UNSUPPORTED_FEATURE;
	}

	/* Check if enabled */
	if(!pTstin->batteryTest.testEnable)
	{
		return RC_TEST_DISABLED;
	}

	/* Invalidate last test results */
	pTstin->batteryTest.testDataValid = TSTIN_RESULTS_INVALID;

	/* Measure Battery */
	ProSLIC_LineMonitor(pProslic,&monitor);

	pTstin->batteryTest.vbat.value = monitor.vbat;

	pTstin->batteryTest.testResult = logTest(pProslic,&(pTstin->batteryTest.vbat),"Battery : VBAT");

	pTstin->batteryTest.testDataValid = TSTIN_RESULTS_VALID;   /* New valid results */

	return (pTstin->batteryTest.testResult);
}
Esempio n. 5
0
int Process::waitFork()
{
  int limit   = RETRY_FORK_LIMIT;
  int timeout = RETRY_FORK_INTERVAL;

  int pid;

  for (int i = 0; i < limit; i++)
  {
    logTest("Process::waitFork", "Trying at %s",
                strMsTimestamp());

    //
    // It could optionally try again only if the
    // error code is 11, 'Resource temporarily
    // unavailable'.
    //

    if ((pid = fork()) >= 0)
    {
      break;
    }
    else if (i < limit - 1)
    {
      logTest("Process::waitFork::fork", "Function "
                     "fork failed");

      logError("Process::waitFork::fork", EGET());


      logTest("Process::waitFork", "Trying again");

      usleep(timeout * 1000);
    }
  }

  if (pid <= 0)
  {
    logTest("Process::waitFork", "Returning at %s",
                strMsTimestamp());
  }

  return pid;
}
Esempio n. 6
0
int Process::addParameter(const char *parameter)
{
  logTrace("Process::addParameter");

  if (function_ != NULL)
  {
    logTest("Process::addParameter", "Can't add a parameter "
                "to a function");

    logError("Process::addParameter", ESET(EPERM));

    return -1;
  }
  else if (nextParameter_ < 2)
  {
    logTest("Process::addParameter", "Can't add a parameter "
                "without a command");

    logError("Process::addParameter", ESET(EPERM));

    return -1;
  }

  if (nextParameter_ < parametersLimit_)
  {
    if (setValue(parameters_[nextParameter_], parameter) > 0)
    {
      nextParameter_++;

      return 1;
    }
  }
  else
  {
    logTest("Process::addParameter", "No space left in the "
                "parameter table");

    logError("Process::addParameter", ESET(ENOMEM));
  }

  return -1;
}
Esempio n. 7
0
FILE *Process::getNullStream()
{
  logTrace("Process::getNullStream");

  if (nullStream_ == NULL)
  {
    logTest("Process::getNullStream", "Creating a "
                "fake stream as '%s'", nullStreamName_);

    if ((nullStream_ = fopen(nullStreamName_, "a+")) == NULL)
    {
      logError("Process::getNullStream::fopen", EGET());

      logTest("Process::getNullStream", "Can't create "
                  "a fake stream as '%s'", nullStreamName_);
    }
  }

  return nullStream_;
}
Esempio n. 8
0
int processHandler(int fd)
{
  logTest("processHandler", "Going to run a new process");

  for (;;)
  {
    for (int i = 0; i < DEFAULT_PROCESS_ENTRIES; i++)
    {
      if (processes[i] == NULL)
      {
        logTest("processHandler", "Starting process for descriptor %d", fd);

        processes[i] = new Process();

        processes[i] -> setFunction(requestHandler, NULL);

        processes[i] -> setStdin(fd);
        processes[i] -> setStdout(fd);
        processes[i] -> setStderr(fileno(stderr));

        processes[i] -> start();

        return 1;
      }
    }

    //
    // We were unable to find a slot.
    // Wait until a child exits.
    //

    logTest("processHandler", "No free slots found");

    processes[0] -> wait(getTimestamp(10));

    processCheck();
  }
}
Esempio n. 9
0
void RunTest()
{
/*
FIXME

  extern void InstallSignals();

  logTest("RunTest", "Going to install the signal handlers");

  InstallSignals();
*/
  logTest("RunTest", "Going to run the connection handler");

  connectionHandler();

  logTest("RunTest", "Going to exit with %d requests handled",
              requests);
/*
FIXME

  HandleCleanup();
*/
}
Esempio n. 10
0
int Process::kill(int signal)
{
  logTrace("Process::kill");

  logTest("Process::kill", "Sending signal %d to process %d",
              signal, pid_);

  if (::kill(pid_, signal) < 0 && EGET() != ESRCH)
  {
    logError("Process::kill::kill", EGET());

    return -1;
  }

  return 1;
}
Esempio n. 11
0
FILE *Process::setDescriptorStream(int &fd, FILE *&stream, char *mode)
{
  logTrace("Process::setDescriptorStream");

  if ((stream = fdopen(fd, mode)) == NULL)
  {
    logError("Process::setDescriptorStream::fdopen", EGET());

    logTest("Process::setDescriptorStream", "Can't create "
                "stream for descriptor %d", fd);

    return getNullStream();
  }

  return stream;
}
Esempio n. 12
0
int Process::wait(const T_timestamp timeout)
{
  logTrace("Process::wait");

  if (pid_ < 0)
  {
    logError("Process::wait", ESET(ECHILD));

    return 1;
  }

  //
  // Wait for the process until the timeout.
  //

  int status;

  int options = WUNTRACED;

  setTimer(timeout);

  int result;

  if ((result = waitpid(pid_, &status, options)) == -1)
  {
    if (EGET() == EINTR)
    {
      logTest("Process::wait", "Timeout raised waiting "
                  "for pid %d", pid_);

      return 0;
    }
    else
    {
      logError("Process::wait", EGET());

      return -1;      
    }
  }

  resetTimer();

  result = parseStatus(result, status);

  return result;
}
Esempio n. 13
0
int Process::isSuccess()
{
  logTrace("Process::isSuccess");

  if (status_ == -1)
  {
    logTest("Process::isSuccess", "Child %d is "
                "still running", pid_);

    logWarning("Process::isSuccess", ESET(EPERM));

    return 0;
  }

  if (WIFEXITED(status_))
  {
    return (WEXITSTATUS(status_) == 0);
  }

  return 0;
}
Esempio n. 14
0
int Process::addEnvironment(const char *environment)
{
  logTrace("Process::addEnvironment");

  if (nextEnvironment_ < environmentLimit_)
  {
    if (setValue(environment_[nextEnvironment_], environment) > 0)
    {
      nextEnvironment_++;

      return 1;
    }
  }
  else
  {
    logTest("Process::addEnvironment", "No space left in the "
                "environment table");

    logError("Process::addEnvironment", ESET(ENOMEM));
  }

  return -1;
}
Esempio n. 15
0
Process::~Process()
{
  logTrace("Process::~Process");

  //
  // Close all the descriptors.
  //

  end();

  if (nullStream_  != NULL)
  {
    logTest("Process::~Process", "Closing the null stream");

    fclose(nullStream_);

    nullStream_ = NULL;
  }

  //
  // Free memory from the heap.
  //

  if (function_ == NULL)
  {
    for (int i = 0; i < nextParameter_; i++)
    {
      delete [] parameters_[i];
    }
  }

  for (int i = 0; i < nextEnvironment_; i++)
  {
    delete [] environment_[i];
  }
}
Esempio n. 16
0
/* *********************************** */
int ProSLIC_testInAudio(proslicChanType *pProslic, proslicTestInObjType *pTstin)
{
uInt8 enhanceRegSave;
uInt8 lf;
int32 data;
int32 gainMeas1,gainMeas2;
int32 gainMeas3 = 0;
ProSLIC_audioGain_Cfg gainCfg;
int32 Pin = -3980;   /* -10dBm + 6.02dB (since OHT w/ no AC load) */

	/* Valid device check */
	if(TSTIN_INVALID_PART_NUM)
	{
		return RC_UNSUPPORTED_FEATURE;
	}

	/* Check if enabled */
	if(!pTstin->audioTest.testEnable)
	{
		return RC_TEST_DISABLED;
	}

	/* Invalidate last test results */
	pTstin->audioTest.testDataValid = TSTIN_RESULTS_INVALID;

	/* Verify line not in use */
	if(ProSLIC_ReadReg(pProslic,34) & 0x02)  /* LCR */
	{
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("\nProSLIC : TestIn : Audio : Line in Use\n");
		}
#endif
		if(pTstin->audioTest.abortIfLineInUse == ABORT_LIU_ENABLED)
		{
			return RC_LINE_IN_USE;
		}
	}

	/* Disable Powersave */
	enhanceRegSave = ProSLIC_ReadReg(pProslic,47);
	ProSLIC_WriteReg(pProslic,47,0x20);
	Delay(pProTimer,10);


	/* Setup Audio Filter, enable audio in OHT */
	lf = ProSLIC_ReadReg(pProslic,30);  /* LINEFEED */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	Delay(pProTimer,20); /* settle */
	setup1kHzBandpass(pProslic);
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_OHT);

	/* Setup osc1 for 1kHz -10dBm tone, disable hybrid, enable filters */
	ProSLIC_WriteRAM(pProslic,26,0x5A80000L); /* OSC1FREQ */
	ProSLIC_WriteRAM(pProslic,27,0x5D8000L);  /* OSC1AMP */
	ProSLIC_WriteReg(pProslic,48,0x02);       /* OMODE */
	ProSLIC_WriteReg(pProslic,49,0x01);       /* OCON */
	ProSLIC_WriteReg(pProslic,44,0x10);       /* DIGCON */
	ProSLIC_WriteReg(pProslic,71,0x10);       /* DIAG1 */

	/* Settle */
	Delay(pProTimer,800);

	/* Read first gain measurement (Gtx + Grx + Gzadj) */
	gainMeas1 = readAudioDiagLevel(pProslic,pTstin->audioTest.zerodBm_mVpk);

	/* Bypass TXACHPF and set TXACEQ to unity */
	gainCfg.acgain = ProSLIC_ReadRAM(pProslic,544);  /* TXACGAIN */
	gainCfg.aceq_c0 = ProSLIC_ReadRAM(pProslic,540); /* TXACEQ_C0 */
	gainCfg.aceq_c1 = ProSLIC_ReadRAM(pProslic,541); /* TXACEQ_C1 */
	gainCfg.aceq_c2 = ProSLIC_ReadRAM(pProslic,542); /* TXACEQ_C2 */
	gainCfg.aceq_c3 = ProSLIC_ReadRAM(pProslic,543); /* TXACEQ_C3 */
	ProSLIC_WriteRAM(pProslic,544,0x8000000L); 
	ProSLIC_WriteRAM(pProslic,543,0x0L);
	ProSLIC_WriteRAM(pProslic,542,0x0L);
	ProSLIC_WriteRAM(pProslic,541,0x0L);
	ProSLIC_WriteRAM(pProslic,540,0x8000000L);
	ProSLIC_WriteReg(pProslic,44,0x18);

	/* Settle */
	Delay(pProTimer,800);

	/* Read second level measurement (RX level only) */
	gainMeas2 = readAudioDiagLevel(pProslic,pTstin->audioTest.zerodBm_mVpk);

	/* Adjust txgain if TXACGAIN wasn't unity during gainMeas1 */
	if(gainCfg.acgain != 0x8000000L)
	{
		data = (gainCfg.acgain*10)/134217;
		gainMeas3 = dBLookup(data);
	}

	/* Computations */
	pTstin->audioTest.rxGain.value = gainMeas2 - Pin;
	pTstin->audioTest.txGain.value = gainMeas1 - gainMeas2 + gainMeas3;
	
#ifdef ENABLE_DEBUG
	if(pProslic->debugMode)
	{
		LOGPRINT("ProSLIC : TestIn : Audio : gainMeas1 = %d\n", gainMeas1);
		LOGPRINT("ProSLIC : TestIn : Audio : gainMeas2 = %d\n", gainMeas2);
		LOGPRINT("ProSLIC : TestIn : Audio : gainMeas3 = %d\n", gainMeas3);
	}
#endif
	pTstin->audioTest.testResult = RC_TEST_PASSED;
	pTstin->audioTest.testResult |= logTest(pProslic,&(pTstin->audioTest.rxGain),"RX Path Gain");
	pTstin->audioTest.testResult |= logTest(pProslic,&(pTstin->audioTest.txGain),"TX Path Gain");



	/*
	** Restore 
	*/

	/* Need to store/restore all modified reg/RAM */
	ProSLIC_WriteRAM(pProslic,544,gainCfg.acgain); 
	ProSLIC_WriteRAM(pProslic,540,gainCfg.aceq_c0);
	ProSLIC_WriteRAM(pProslic,541,gainCfg.aceq_c1);
	ProSLIC_WriteRAM(pProslic,542,gainCfg.aceq_c2);
	ProSLIC_WriteRAM(pProslic,543,gainCfg.aceq_c3);

	ProSLIC_WriteReg(pProslic,71,0x0);  /* DIAG1 */
	ProSLIC_WriteReg(pProslic,44,0x0);  /* DIGCON */
	ProSLIC_WriteReg(pProslic,48,0x0);  /* OMODE */
	ProSLIC_WriteReg(pProslic,49,0x0);  /* OCON */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	ProSLIC_WriteReg(pProslic,47,enhanceRegSave);
	ProSLIC_SetLinefeedStatus(pProslic,lf);

	/* Validate last test results */
	pTstin->audioTest.testDataValid = TSTIN_RESULTS_VALID;

	return pTstin->audioTest.testResult;
}
Esempio n. 17
0
int Process::start()
{
  logTrace("Process::start");

  int childIn[2]  = { -1, -1 };
  int childOut[2] = { -1, -1 };
  int childErr[2] = { -1, -1 };

  //
  // We either have 2 parameters and this process
  // will exec() a new command, or we have one or
  // none and this process will yield control to
  // a function.
  //

  if (function_ == NULL && (parameters_[0] == NULL ||
          parameters_[1] == NULL))
  {
    logTest("Process::start", "Can't start the process "
                "without a command or function");

    logError("Process::start", ESET(EPERM));

    return -1;
  }

  #ifdef TEST

  if (function_ == NULL)
  {
    logTest("Process::start", "Executing command '%s'",
                parameters_[0]);

    for (int i = 1; i < parametersLimit_ &&
             parameters_[i] != NULL; i++)
    {
      logTest("Process::start", "Parameter [%d] is '%s'",
                  i, parameters_[i]);
    }
  }
  else
  {
    logTest("Process::start", "Executing function at %p",
                function_);

    logTest("Process::start", "Passing data as %p",
                parameters_[0]);
  }

  for (int i = 0; i < environmentLimit_ &&
           environment_[i] != NULL; i++)
  {
    logTest("Process::start", "Environment [%d] is '%s'",
                i, environment_[i]);
  }

  #endif

  //
  // Create the pipes that will be used to replace
  // the standard descriptors.
  //

  if ((in_ == -1 && pipe(childIn) != 0) ||
          (out_ == -1 && pipe(childOut) != 0) ||
              (err_ == -1 && pipe(childErr) != 0))
  {
    logError("Process::start::pipe", EGET());

    return -1;
  }

  //
  // The fork() on Cygwin can show intermittent
  // failures. In this case we try again after
  // some time.
  //

  #ifdef __CYGWIN32__

  switch (pid_ = waitFork())

  #else

  switch (pid_ = fork())

  #endif

  {
    case -1:
    {
      //
      // An error was encountered.
      //

      logError("Process::start::fork", EGET());

      if (in_ == -1)
      {
        close(childIn[0]);
        close(childIn[1]);
      }

      if (out_ == -1)
      {
        close(childOut[0]);
        close(childOut[1]);
      }

      if (err_ == -1)
      {
        close(childErr[0]);
        close(childErr[1]);
      }

      return -1;
    }
    case 0:
    {
      //
      // We are the child process.
      //

      logTest("Process::start", "Child running with pid %d", getpid());

      //
      // Drop the privileges.
      //

      if (privileged_ != 1)
      {
        logTest("Process::start", "Child dropping the permissions");

        setgid(getgid());
        setuid(getuid());
      }

      //
      // Let the input descriptor inherited from the
      // parent replace the standard descriptors. The
      // descriptor can be either the one set by the
      // parent or our end of the pipe we created be-
      // fore forking.
      //
      // Handle the standard input.
      //

      if (in_ == -1)
      {
        logTest("Process::start", "Child replacing pipe "
                    "%d and %d for input", childIn[0], childIn[1]);

        if (childIn[0] != 0)
        {
          dup2(childIn[0], 0);

          close(childIn[0]);
        }

        close(childIn[1]);
      }
      else if (in_ != 0)
      {
        logTest("Process::start", "Child replacing input %d", in_);

        dup2(in_, 0);

        if (in_ != out_ && in_ != err_)
        {
          close(in_);
        }
      }
      else
      {
        logTest("Process::start", "Child inherited input");
      }

      in_ = 0;

      //
      // Handle the standard output.
      //

      if (out_ == -1)
      {
        logTest("Process::start", "Child replacing pipe "
                    "%d and %d for output", childOut[0], childOut[1]);

        if (childOut[1] != 1)
        {
          dup2(childOut[1], 1);

          close(childOut[1]);
        }

        close(childOut[0]);
      }
      else if (out_ != 1)
      {
        logTest("Process::start", "Child replacing output %d", out_);

        dup2(out_, 1);

        if (out_ != err_)
        {
          close(out_);
        }
      }
      else
      {
        logTest("Process::start", "Child inherited output");
      }

      out_ = 1;

      //
      // Handle the standard error.
      //

      if (err_ == -1)
      {
        logTest("Process::start", "Child replacing pipe "
                    "%d and %d for error", childErr[0], childErr[1]);

        if (childErr[1] != 2)
        {
          dup2(childErr[1], 2);

          close(childErr[1]);
        }

        close(childErr[0]);
      }
      else if (err_ != 2)
      {
        logTest("Process::start", "Child replacing error %d", err_);

        dup2(err_, 2);

        close(err_);
      }
      else
      {
        logTest("Process::start", "Child inherited error");
      }

      err_ = 2;

      //
      // Let the pid be our own pid.
      //

      pid_ = getpid();

      logTest("Process::start", "Child has descriptors "
                  "%d, %d, %d and pid %d", in_, out_, err_, pid_);

      //
      // Set the new environment for the process.
      //

      for (int i = 0; i < environmentLimit_ &&
               environment_[i] != NULL; i++)
      {
        putenv(environment_[i]);
      }

      //
      // Either execute the requested command or
      // yield control to the function.
      //

      if (parameters_[1] != NULL)
      {
        if (execvp(parameters_[0], parameters_ + 1) == -1)
        {
          logTest("Process::start", "Child failed to execute the command");

          logError("Process::start::execvp", EGET());
        }

        exitStatus(-1);
      }
      else
      {
        int result = function_((void *) parameters_[0]);

        exitStatus(result);
      }
    }
    default:
    {
      //
      // We are the parent process.
      //

      logTest("Process::start", "Parent started child with pid %d", pid_);

      if (in_ == -1)
      {
        close(childIn[0]);

        in_ = childIn[1];
      }

      if (out_ == -1)
      {
        close(childOut[1]);

        out_ = childOut[0];
      }

      if (err_ == -1)
      {
        close(childErr[1]);

        err_ = childErr[0];
      }

      logTest("Process::start", "Parent using descriptors %d, %d, %d",
                  in_, out_, err_);

      return 1;
    }
  }
}
Esempio n. 18
0
int ProSLIC_testInDCFeed(proslicChanType *pProslic, proslicTestInObjType *pTstin)
{
uInt8 enhanceRegSave;
proslicMonitorType monitor;
ramData lcroffhk_save;
ramData lcronhk_save;

	/* Valid device check */
	if(TSTIN_INVALID_PART_NUM)
	{
		return RC_UNSUPPORTED_FEATURE;
	}

	/* Check if enabled */
	if(!pTstin->dcFeedTest.testEnable)
	{
		return RC_TEST_DISABLED;
	}

	/* Invalidate last test results */
	pTstin->dcFeedTest.testDataValid = TSTIN_RESULTS_INVALID;

	/* Verify line not in use */
	if(ProSLIC_ReadReg(pProslic,34) & 0x02)  /* LCR */
	{
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("\nProSLIC : TestIn : DC Feed : Line in Use\n");
		}
#endif
		if(pTstin->dcFeedTest.abortIfLineInUse==ABORT_LIU_ENABLED)
		{
			return RC_LINE_IN_USE;
		}
	}

	/* Disable Powersave */
	enhanceRegSave = ProSLIC_ReadReg(pProslic,47);
	ProSLIC_WriteReg(pProslic,47,0x20);
	Delay(pProTimer,10);

	/* Onhook measurement */
	ProSLIC_LineMonitor(pProslic,&monitor);
	
	pTstin->dcFeedTest.dcfeedVtipOnhook.value = monitor.vtip;
	pTstin->dcFeedTest.dcfeedVringOnhook.value = monitor.vring;
	pTstin->dcFeedTest.dcfeedVloopOnhook.value = monitor.vtr;
	pTstin->dcFeedTest.dcfeedVbatOnhook.value = monitor.vbat;
	pTstin->dcFeedTest.dcfeedItipOnhook.value = monitor.itip;
	pTstin->dcFeedTest.dcfeedIringOnhook.value = monitor.iring;
	pTstin->dcFeedTest.dcfeedIloopOnhook.value = monitor.itr;
	pTstin->dcFeedTest.dcfeedIlongOnhook.value = monitor.ilong;

	/* Modify LCR threshold (optional) before connecting test load */
	if(pTstin->dcFeedTest.applyLcrThresh == LCR_CHECK_ENABLED)
	{
		lcroffhk_save = ProSLIC_ReadRAM(pProslic,852);
		lcronhk_save = ProSLIC_ReadRAM(pProslic,853);
		ProSLIC_WriteRAM(pProslic,852,pTstin->dcFeedTest.altLcrOffThresh);
		ProSLIC_WriteRAM(pProslic,853,pTstin->dcFeedTest.altLcrOnThresh);
	}

	/* Connect internal test load for 2nd dc feed i/v point */
	setInternalTestLoad(pProslic,1);
	Delay(pProTimer,50);
	/* Offhook measurement */
	ProSLIC_LineMonitor(pProslic,&monitor);
	
	pTstin->dcFeedTest.dcfeedVtipOffhook.value = monitor.vtip;
	pTstin->dcFeedTest.dcfeedVringOffhook.value = monitor.vring;
	pTstin->dcFeedTest.dcfeedVloopOffhook.value = monitor.vtr;
	pTstin->dcFeedTest.dcfeedVbatOffhook.value = monitor.vbat;
	pTstin->dcFeedTest.dcfeedItipOffhook.value = monitor.itip;
	pTstin->dcFeedTest.dcfeedIringOffhook.value = monitor.iring;
	pTstin->dcFeedTest.dcfeedIloopOffhook.value = monitor.itr;
	pTstin->dcFeedTest.dcfeedIlongOffhook.value = monitor.ilong;

	pTstin->dcFeedTest.testResult = RC_TEST_PASSED;  /* initialize */
	/* Read LCR */
	if(ProSLIC_ReadReg(pProslic,34) & 0x07)  /* LCRRTP */
	{
		pTstin->dcFeedTest.lcrStatus = 1;
	}
	else
	{
		pTstin->dcFeedTest.lcrStatus = 0;
	}

	/* Only fail check if enabled */
	if(pTstin->dcFeedTest.applyLcrThresh == LCR_CHECK_ENABLED)
	{
		pTstin->dcFeedTest.testResult |= !pTstin->dcFeedTest.lcrStatus;
	}

	/* Disconnect Test Load */
	setInternalTestLoad(pProslic,0);

	/* Restore LCR thresholds */
	if(pTstin->dcFeedTest.applyLcrThresh == LCR_CHECK_ENABLED)
	{
		ProSLIC_WriteRAM(pProslic,852,lcroffhk_save);
		ProSLIC_WriteRAM(pProslic,853,lcronhk_save);
	}

	/* Restore enhance reg */
    ProSLIC_WriteReg(pProslic,47,enhanceRegSave);  

	/* Process Results */
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVtipOnhook),"DcFeed : Vtip Onhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVringOnhook),"DcFeed : Vring Onhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVloopOnhook),"DcFeed : Vloop Onhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVbatOnhook),"DcFeed : Vbat Onhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedItipOnhook),"DcFeed : Itip Onhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIringOnhook),"DcFeed : Iring Onhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIloopOnhook),"DcFeed : Iloop Onhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIlongOnhook),"DcFeed : Ilong Onhook");

	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVtipOffhook),"DcFeed : Vtip Offhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVringOffhook),"DcFeed : Vring Offhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVloopOffhook),"DcFeed : Vloop Offhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedVbatOffhook),"DcFeed : Vbat Offhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedItipOffhook),"DcFeed : Itip Offhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIringOffhook),"DcFeed : Iring Offhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIloopOffhook),"DcFeed : Iloop Offhook");
	pTstin->dcFeedTest.testResult |= logTest(pProslic,&(pTstin->dcFeedTest.dcfeedIlongOffhook),"DcFeed : Ilong Offhook");

	logStatus(pProslic,pTstin->dcFeedTest.lcrStatus,"DcFeed : LCR");


	pTstin->dcFeedTest.testDataValid = 1;   /* New valid results */

	/* return cumulative pass/fail result */

	return (pTstin->dcFeedTest.testResult);
}
Esempio n. 19
0
int connectionHandler()
{
  requests = 0;

  logTest("connectionHandler", "Going to create a new dispatcher");

  dispatcher = new Dispatcher();

  dispatcher -> start();

  logTest("connectionHandler", "Going to create a new listener");

  listener = new TcpListener();

  listener -> setPort(6001);
  listener -> setBacklog(32);

  //
  // Not needed for the early tests.
  //
  // listener -> setAccept("127.0.0.1");
  //

  listener -> start();

  logTest("connectionHandler", "Going to add the listener to the set");

  dispatcher -> addReadFd(listener -> getFd());

  logTest("connectionHandler", "Going to enter the main loop");

  T_timestamp start = getTimestamp();
  T_timestamp now   = getTimestamp();

  int result;
  int fd;

  T_timestamp timeout;

  while (diffTimestamp(start, now) < 1000000000)
  {
    logTest("connectionHandler", "Going to wait for new events");

    timeout = nullTimestamp();

    result = dispatcher -> waitEvent(timeout);

    logTest("connectionHandler", "Dispatcher returned %d", result);

    while ((fd = dispatcher -> nextReadEvent()) != -1)
    {
      if ((fd = listener -> accept()) != -1)
      {
        requests++;

        logTest("connectionHandler", "Going to handle request %d",
                    requests);

        processHandler(fd);
      }
    }

    processCheck();

    now = getTimestamp();
  }

  logTest("connectionHandler", "Exiting with %ld seconds elapsed since start",
              diffTimestamp(start, now) / 1000);

  dispatcher -> removeReadFd(listener -> getFd());

  dispatcher -> end();

  delete dispatcher;

  logTest("connectionHandler", "Deleted the dispatcher");

  listener -> end();

  delete listener;

  logTest("connectionHandler", "Deleted the listener");

  processWait();

  return requests;
}
Esempio n. 20
0
int requestHandler(void *)
{
  logTest("requestHandler", "Going to handle the new request");

  for (int i = 0; i < DEFAULT_PROCESS_ENTRIES; i++)
  {
    if (processes[i] != NULL)
    {
      logTest("requestHandler", "Cleaning up process table");

      delete processes[i];

      processes[i] = NULL;
    }
  }

  logTest("requestHandler", "Cleaning up listener and dispatcher");

  delete listener;

  listener = NULL;

  delete dispatcher;

  dispatcher = NULL;

  char buffer[DEFAULT_BUFFER_LENGTH];

  //
  // Create the class for parsing and
  // handling the HTTP request.
  //

  Request *request = new Request();

/*
FIXME
*/
  request -> setRootPath("/home/pinzari/NX/apache_1.3.33/htdocs/manual");
/*
  request -> setRootPath("/usr/share/doc/HTML");
*/
  request -> setProgramPath("/home/pinzari/NX/nxproxy");
  request -> setProgramName("nxproxy");

  for (;;)
  {
    logTest("requestHandler", "Reading from descriptor %d",
                fileno(stdin));

/*
FIXME: This is temporarily used to dump the content of
       data sent by X clients at connection time.
*/

    char data[1024];

    int result;

    while ((result = read(0, data, 1024)) > 0)
    {
      logDump("requestHandler", data, result);
    }

    logTest("requestHandler", "Exiting");

    exit(0);

    if (fgets(buffer, sizeof(buffer), stdin) != NULL)
    {
      //
      // We are waiting for 1, when the request is
      // complete, or -1, in the case of an error.
      //

      if (request -> parse(buffer, strlen(buffer)) != 0)
      {
        break;
      }
    }
  }

  if (request -> isError() != request_error_none)
  {
    logTest("requestHandler", "Aborting request with error '%s'",
                request -> getErrorString());
  }
  else
  {
    logTest("requestHandler", "Executing request with URL '%s'",
                request -> getUrl());
  }

  //
  // Read from the file and write to the socket.
  //

  const char *name = request -> getFile();

  if (name != NULL)
  {
    int in  = open(name, O_RDONLY);

    if (in != -1)
    {
      int out = fileno(stdout);

      write(out, "HTTP/1.1 200 OK", strlen("HTTP/1.1 200 OK"));
      write(out, "Content-type: ", strlen("Content-Type: "));
      write(out, request -> getMimeString(),
                strlen(request -> getMimeString()));
      write(out, "\n\n", strlen("\n\n"));

      int result;

      while ((result = read(in, buffer, sizeof(buffer))) > 0)
      {
        write(fileno(stdout), buffer, result);
      }
    }
  }

  fclose(stdin);
  fclose(stdout);

  delete request;

  logTest("requestHandler", "Exiting from the request handler");

  return 1;
}
Esempio n. 21
0
/* *********************************** */
int ProSLIC_testInRinging(proslicChanType *pProslic, proslicTestInObjType *pTstin)
{
uInt8 ringcon_save,enhance_save;
int32 vtr[MAX_RINGING_SAMPLES];
int i;
uInt8 lf;
uInt32 rtper_save, ringfr_save,ringamp_save,ringof_save,rtacth_save,rtdcth_save;
ProSLIC_DCfeed_Cfg dcfeedCfg;

	/* Valid device check */
	if(TSTIN_INVALID_PART_NUM)
	{
		return RC_UNSUPPORTED_FEATURE;
	}

	/* Check if enabled */
	if(!pTstin->ringingTest.testEnable)
	{
		return RC_TEST_DISABLED;
	}

	/* Verify line not in use */
	if(ProSLIC_ReadReg(pProslic,34) & 0x02)  /* LCR */
	{
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("\nProSLIC : TestIn : Ringing : Line in Use\n");
		}
#endif
		if(pTstin->ringingTest.abortIfLineInUse)
		{
			return RC_LINE_IN_USE;
		}
	}

	/* Invalidate last test results */
	pTstin->ringingTest.testDataValid = TSTIN_RESULTS_INVALID;

	/* Check sample size/rate */
	if(pTstin->ringingTest.numSamples > MAX_RINGING_SAMPLES)
		pTstin->ringingTest.numSamples = MAX_RINGING_SAMPLES;

	if(pTstin->ringingTest.sampleInterval > MAX_RINGING_SAMPLE_INTERVAL)
		pTstin->ringingTest.sampleInterval = MAX_RINGING_SAMPLE_INTERVAL;

	if(pTstin->ringingTest.sampleInterval < MIN_RINGING_SAMPLE_INTERVAL)
		pTstin->ringingTest.sampleInterval = MIN_RINGING_SAMPLE_INTERVAL;

	/* Disable Powersave */
	enhance_save = ProSLIC_ReadReg(pProslic,47);
	ProSLIC_WriteReg(pProslic,47,0x20);
	Delay(pProTimer,10);

	/* Disable ring cadencing */
	ringcon_save = ProSLIC_ReadReg(pProslic,38); /* RINGCON */
	ProSLIC_WriteReg(pProslic,38,ringcon_save&0xE7); /* RINGCON */

	/* Must enter ringing through active state */
	lf = ProSLIC_ReadReg(pProslic,30);  /* LINEFEED */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	Delay(pProTimer,20); /* settle */

	/* Start ringing */
	ProSLIC_SetLinefeedStatus(pProslic,LF_RINGING);
	Delay(pProTimer,500);

	/* Verify Ring Started */
	if(ProSLIC_ReadReg(pProslic,30) != 0x44)
	{
		ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
		ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN);
        ProSLIC_WriteReg(pProslic,38,ringcon_save);
		ProSLIC_WriteReg(pProslic,47,enhance_save);
		ProSLIC_SetLinefeedStatus(pProslic,lf);
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("ProSLIC : TestIn : Ringing : Ring Start Fail\n");
		}
#endif
		pTstin->ringingTest.testResult = RC_TEST_FAILED;
		return RC_RING_START_FAIL;
	}

	/* Capture samples */
	pTstin->ringingTest.ringingVdc.value = 0;
	for(i=0;i<pTstin->ringingTest.numSamples;i++)
	{
		vtr[i] = ProSLIC_ReadMADCScaled(pProslic,69,0); /* VDIFF_FILT */
		pTstin->ringingTest.ringingVdc.value += vtr[i];
#ifdef ENABLE_DEBUG
		if(pProslic->debugMode)
		{
			LOGPRINT("ProSLIC : TestIn : Ringing : Vtr[%d] = %d\n",i,vtr[i]);
		}
#endif
		Delay(pProTimer,pTstin->ringingTest.sampleInterval);
	}
	
	/* Restore linefeed */
	ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
	Delay(pProTimer,20);

    /* Process Results */
	pTstin->ringingTest.ringingVdc.value /= pTstin->ringingTest.numSamples;
	for(i=0;i<pTstin->ringingTest.numSamples;i++)
	{
		vtr[i] -= pTstin->ringingTest.ringingVdc.value;
		pTstin->ringingTest.ringingVac.value += ((vtr[i]/100L) * (vtr[i]/100L));
	}


	pTstin->ringingTest.ringingVac.value /= pTstin->ringingTest.numSamples;
	pTstin->ringingTest.ringingVac.value = Isqrt32(pTstin->ringingTest.ringingVac.value);
	pTstin->ringingTest.ringingVac.value *= 100L;

	pTstin->ringingTest.testResult = RC_TEST_PASSED;
	pTstin->ringingTest.testResult |= logTest(pProslic,&(pTstin->ringingTest.ringingVdc),"Ringing : VDC");
	pTstin->ringingTest.testResult |= logTest(pProslic,&(pTstin->ringingTest.ringingVac),"Ringing : VAC");
	/*
	** Optional Ringtrip Test 
	*/

	if(pTstin->ringingTest.ringtripTestEnable == RTP_CHECK_ENABLED)
	{
		/* Setup low voltage linefeed so low level ringing may be used */
		ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN);
		storeDCFeedPreset(pProslic,&dcfeedCfg);
		ProSLIC_DCFeedSetupCfg(pProslic,ringtripTestDCFeedPreset,0);

		/* Optional Ringtrip Test (modified ringer settings to use test load to trip) */
		rtper_save = ProSLIC_ReadRAM(pProslic,755);
		ringfr_save = ProSLIC_ReadRAM(pProslic,844);
		ringamp_save = ProSLIC_ReadRAM(pProslic,845);
		ringof_save = ProSLIC_ReadRAM(pProslic,843);
		rtacth_save = ProSLIC_ReadRAM(pProslic,848);
		rtdcth_save = ProSLIC_ReadRAM(pProslic,847);

		ProSLIC_WriteRAM(pProslic,755,0x50000L);  /* RTPER */
		ProSLIC_WriteRAM(pProslic,844,0x7EFE000L);/* RINGFR */
		ProSLIC_WriteRAM(pProslic,845,0xD6307L);  /* RINGAMP */
		ProSLIC_WriteRAM(pProslic,843,0x0L);      /* RINGOF */
		ProSLIC_WriteRAM(pProslic,848,0x7827FL);  /* RTACTH */
		ProSLIC_WriteRAM(pProslic,847,0xFFFFFFFL);/* RTDCTH */

		/* Start ringing from active state */
		ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
		Delay(pProTimer,20);
		ProSLIC_SetLinefeedStatus(pProslic,LF_RINGING);
		Delay(pProTimer,200);

			/* Verify Ring Started */
		if(ProSLIC_ReadReg(pProslic,30) != 0x44)
		{
			ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
			ProSLIC_SetLinefeedStatus(pProslic,LF_OPEN);
			ProSLIC_WriteReg(pProslic,38,ringcon_save);
			ProSLIC_WriteReg(pProslic,47,enhance_save);
			ProSLIC_SetLinefeedStatus(pProslic,lf);
#ifdef ENABLE_DEBUG
			if(pProslic->debugMode)
			{
				LOGPRINT("ProSLIC : TestIn : Ringtrip : Ring Start Fail\n");
			}
#endif
			pTstin->ringingTest.testResult=RC_TEST_FAILED;
			return RC_RING_START_FAIL;
		}

		/* Connect Test Load to cause ringtrip */
	    setInternalTestLoad(pProslic,1);
		Delay(pProTimer,200);

		/* Check for RTP */
		if(ProSLIC_ReadReg(pProslic,34) & 0x01)  /* LCRRTP */
		{
			pTstin->ringingTest.rtpStatus = 1;
		    pTstin->ringingTest.testResult |= RC_TEST_PASSED;
		}
		else
		{
			pTstin->ringingTest.rtpStatus = 0;
			pTstin->ringingTest.testResult |= RC_TEST_FAILED;
			ProSLIC_SetLinefeedStatus(pProslic,LF_FWD_ACTIVE);
		}		
	    setInternalTestLoad(pProslic,0);
		Delay(pProTimer,20);

		logStatus(pProslic,pTstin->ringingTest.rtpStatus,"Ringing : RTP");

		/* Restore DC Feed */
		ProSLIC_DCFeedSetupCfg(pProslic,&dcfeedCfg,0);

		/* Restore Ring Settings */
		ProSLIC_WriteRAM(pProslic,755,rtper_save);/* RTPER */
		ProSLIC_WriteRAM(pProslic,844,ringfr_save);/*RINGFR */
		ProSLIC_WriteRAM(pProslic,845,ringamp_save); /* RINGAMP */
		ProSLIC_WriteRAM(pProslic,843,ringof_save); /* RINGOF */
		ProSLIC_WriteRAM(pProslic,848,rtacth_save);/* RTACTH */
		ProSLIC_WriteRAM(pProslic,847,rtdcth_save);/* RTDCTH */

	}/* end of ringtrip test 

	/* Restore Linefeed */
	ProSLIC_SetLinefeedStatus(pProslic,lf);

	/* Restore RINGCON and ENHANCE */
	ProSLIC_WriteReg(pProslic,38,ringcon_save); 
    ProSLIC_WriteReg(pProslic,47,enhance_save);  

	pTstin->ringingTest.testDataValid = TSTIN_RESULTS_VALID;

	return (pTstin->ringingTest.testResult);
}
Esempio n. 22
0
int Process::end()
{
  logTrace("Process::end");

  if (pid_ == -1)
  {
    return 0;
  }

  if (in_ != 0)
  {
    if (inStream_  != NULL)
    {
      logTest("Process::end", "Closing the input stream");

      fclose(inStream_);

      inStream_ = NULL;

      in_ = -1;
    }
    else if (in_ != -1)
    {
      logTest("Process::end", "Closing the input descriptor");

      close(in_);

      in_ = -1;
    }
  }
  else
  {
    logTest("Process::end", "Input is the standard descriptor");
  }

  if (out_ != 1)
  {
    if (outStream_  != NULL)
    {
      logTest("Process::end", "Closing the output stream");

      fclose(outStream_);

      outStream_ = NULL;

      out_ = -1;
    }
    else if (out_ != -1)
    {
      logTest("Process::end", "Closing the output descriptor");

      close(out_);

      out_ = -1;
    }
  }
  else
  {
    logTest("Process::end", "Output is the standard descriptor");
  }

  if (err_ != 2)
  {
    if (errStream_  != NULL)
    {
      logTest("Process::end", "Closing the error stream");

      fclose(errStream_);

      errStream_ = NULL;

      err_ = -1;
    }
    else if (err_ != -1)
    {
      logTest("Process::end", "Closing the error descriptor");

      close(err_);

      err_ = -1;
    }
  }
  else
  {
    logTest("Process::end", "Error is the standard descriptor");
  }

  return 1;
}