summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/common
diff options
context:
space:
mode:
authordotnet-bot <dotnet-bot@microsoft.com>2015-01-30 14:14:42 -0800
committerdotnet-bot <dotnet-bot@microsoft.com>2015-01-30 14:14:42 -0800
commitef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch)
treedee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/pal/tests/palsuite/common
downloadcoreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz
coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2
coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/pal/tests/palsuite/common')
-rw-r--r--src/pal/tests/palsuite/common/ResultBuffer.cpp70
-rw-r--r--src/pal/tests/palsuite/common/ResultBuffer.h44
-rw-r--r--src/pal/tests/palsuite/common/ResultTime.h104
-rw-r--r--src/pal/tests/palsuite/common/pal_stdclib.h25
-rw-r--r--src/pal/tests/palsuite/common/palsuite.h166
5 files changed, 409 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/common/ResultBuffer.cpp b/src/pal/tests/palsuite/common/ResultBuffer.cpp
new file mode 100644
index 0000000000..8d099e8945
--- /dev/null
+++ b/src/pal/tests/palsuite/common/ResultBuffer.cpp
@@ -0,0 +1,70 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+//#include "stdafx.h"
+#include "resultbuffer.h"
+//
+//#using <mscorlib.dll>
+//
+//using namespace System;
+
+
+ResultBuffer:: ResultBuffer(int ThreadCount, int ThreadLogSize)
+ {
+ // Declare an internal status variable
+ int Status=0;
+
+ // Update the maximum thread count
+ MaxThreadCount = ThreadCount;
+
+ // Allocate the memory buffer based on the passed in thread and process counts
+ // and the specified size of the thread specific buffer
+ buffer = NULL;
+ buffer = (char*)malloc(ThreadCount*ThreadLogSize);
+ // Check to see if the buffer memory was allocated
+ if (buffer == NULL)
+ Status = -1;
+ // Initialize the buffer to 0 to prevent bogus data
+ memset(buffer,0,ThreadCount*ThreadLogSize);
+
+ // The ThreadOffset is equal to the total number of bytes that will be stored per thread
+ ThreadOffset = ThreadLogSize;
+
+ }
+
+
+ int ResultBuffer::LogResult(int Thread, char* Data)
+ {
+ // Declare an internal status flad
+ int status = 0;
+
+ // Declare an object to store the offset address into the buffer
+ int Offset;
+
+ // Check to make sure the Thread index is not out of range
+ if(Thread > MaxThreadCount)
+ {
+ Trace("Thread index is out of range, Value of Thread[%d], Value of MaxThreadCount[%d]\n", Thread, MaxThreadCount);
+ status = -1;
+ return(status);
+ }
+
+ // Caculate the offset into the shared buffer based on the process and thread indices
+ Offset = (Thread)*ThreadOffset;
+
+ // Write the passed in data to the reserved buffer
+ memcpy(buffer+Offset,Data,ThreadOffset);
+
+ return(status);
+ }
+
+
+ char* ResultBuffer::getResultBuffer(int threadId)
+ {
+
+ return (buffer + threadId*ThreadOffset);
+
+ }
+
diff --git a/src/pal/tests/palsuite/common/ResultBuffer.h b/src/pal/tests/palsuite/common/ResultBuffer.h
new file mode 100644
index 0000000000..6d32f7fd31
--- /dev/null
+++ b/src/pal/tests/palsuite/common/ResultBuffer.h
@@ -0,0 +1,44 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+//#include <stdio.h>
+//#include <iostream>
+//#include <assert.h>
+#ifndef _RESULT_BUFFER_H_
+#define _RESULT_BUFFER_H_
+
+#include <palsuite.h>
+
+struct ResultData
+{
+ int value;
+ int size;
+// ResultData* NextResult;
+};
+
+ class ResultBuffer
+{
+ // Declare a pointer to a memory buffer to store the logged results
+ char* buffer;
+ // Declare an object to store the maximum Thread count
+ int MaxThreadCount;
+ // Declare and internal data object to store the calculated offset between adjacent threads data sets
+ int ThreadOffset;
+
+ // Declare a linked list object to store the parameter values
+public:
+
+ // Declare a constructor for the single process case
+ ResultBuffer(int ThreadCount, int ThreadLogSize);
+ // Declare a method to log data for the single process instance
+ int LogResult(int Thread, char* Data);
+
+ char* getResultBuffer(int threadId);
+};
+
+#include "resultbuffer.cpp"
+#endif // _RESULT_BUFFER_H_
+
+
diff --git a/src/pal/tests/palsuite/common/ResultTime.h b/src/pal/tests/palsuite/common/ResultTime.h
new file mode 100644
index 0000000000..a52312ed8b
--- /dev/null
+++ b/src/pal/tests/palsuite/common/ResultTime.h
@@ -0,0 +1,104 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+#ifndef _RESULT_TIME_H_
+#define _RESULT_TIME_H_
+
+#include <palsuite.h>
+
+#define DWORD_MAX ((DWORD) 0xFFFFFFFF)
+const char *szDotNetInstallEnvVar = "DOTNET_INSTALL";
+const char *szQASupportDirEnvVar = "QA_SUPPORT_DIR";
+
+#ifdef PLATFORM_UNIX
+#define SEPERATOR "/"
+#else
+#define SEPERATOR "\\"
+#endif
+char *getBuildNumber()
+{
+ char *szBuildFileName = "buildinfo.txt";
+ char *pDirectoryName = NULL;
+ char szBuildFileLoc[256];
+
+ char szTemp[100];
+ // buildinfo.txt contains information in key/value pair
+ char szTempKey[100];
+ char *szTempValue;
+ FILE *fp;
+
+ szTempValue = (char *) malloc (sizeof(char) *100);
+ if (szTempValue == NULL)
+ {
+ Fail("ERROR: Couldn't allocate enough memory to potentially store build number\n");
+ }
+
+#ifndef PLATFORM_UNIX
+ pDirectoryName = getenv(szDotNetInstallEnvVar);
+ if (pDirectoryName == NULL)
+ {
+ /* This condition may exist if the test is being run in say the Dev environment.*/
+ Trace("WARNING: Coriolis Test Environment may not be setup correctly. Variable DOTNET_INSTALL not set\n");
+ _snprintf(szTempValue, 99, "0000.00");
+ return szTempValue;
+ }
+#else
+ pDirectoryName = getenv(szQASupportDirEnvVar);
+ if (pDirectoryName == NULL)
+ {
+ Trace("WARNING: Coriolis Test Environment may not be setup correctly. Variable QA_SUPPORT_DIR not set\n");
+ _snprintf(szTempValue, 99, "0000.00");
+ return szTempValue;
+ }
+
+#endif //PLATFORM_UNIX
+
+#ifndef PLATFORM_UNIX
+ _snprintf(szBuildFileLoc, MAX_PATH, "%s%s%s", pDirectoryName, SEPERATOR, szBuildFileName);
+#else
+ // To avoid buffer overruns for pDirectoryName
+ _snprintf(szBuildFileLoc, MAX_PATH, "%s/../1.0%s%s", pDirectoryName, SEPERATOR, szBuildFileName);
+#endif //PLATFORM_UNIX
+ fp = fopen( szBuildFileLoc, "r");
+ if( fp == NULL)
+ {
+ Trace("WARNING: Couldn't open szBuildFileLoc [%s]\n", szBuildFileLoc);
+ _snprintf(szTempValue, 99, "0000.00");
+ return szTempValue;
+ }
+
+ while( fgets( szTemp, 100, fp ) != NULL)
+ {
+ sscanf(szTemp, "%s %s\n", szTempKey, szTempValue);
+ if(strcmp(szTempKey, "Build-Number:") == 0)
+ {
+ fclose(fp);
+ return szTempValue;
+ }
+ }
+
+ fclose(fp);
+ return szTempValue;
+
+}
+
+DWORD GetTimeDiff( DWORD dwStartTime)
+{
+ DWORD dwDiffTime = 0;
+ DWORD dwEndTime = GetTickCount();
+
+ if( dwEndTime < dwStartTime)
+ {
+ // To account for overflow, we add one
+ dwDiffTime = dwEndTime + (DWORD_MAX - dwStartTime) + 1;
+ }
+ else
+ {
+ dwDiffTime = dwEndTime - dwStartTime;
+ }
+
+ return dwDiffTime;
+}
+#endif // _RESULT_TIME_H_
diff --git a/src/pal/tests/palsuite/common/pal_stdclib.h b/src/pal/tests/palsuite/common/pal_stdclib.h
new file mode 100644
index 0000000000..afde678c9c
--- /dev/null
+++ b/src/pal/tests/palsuite/common/pal_stdclib.h
@@ -0,0 +1,25 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+/*============================================================================
+**
+** Source: pal_stdlib.h
+**
+** Purpose:
+**
+**
+**==========================================================================*/
+
+
+#ifndef __PAL_STDCLIB_H__
+#define __PAL_STDCLIB_H__
+
+/*
+ * <stdio.h> definitions & functions
+ */
+
+#define EOF (-1)
+
+#endif // __PAL_STDCLIB_H__
diff --git a/src/pal/tests/palsuite/common/palsuite.h b/src/pal/tests/palsuite/common/palsuite.h
new file mode 100644
index 0000000000..3f90962a68
--- /dev/null
+++ b/src/pal/tests/palsuite/common/palsuite.h
@@ -0,0 +1,166 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+/*============================================================================
+**
+** Source: palsuite.h
+**
+** Purpose: Define constants and implement functions that are useful to
+** multiple function categories. If common functions are useful
+** only amongst the test cases for a particular function, a separate
+** header file is placed in the root of those test cases.
+**
+**
+**==========================================================================*/
+
+#ifndef __PALSUITE_H__
+#define __PALSUITE_H__
+
+#include <pal.h>
+
+enum
+{
+ PASS = 0,
+ FAIL = 1
+};
+
+
+void Trace(char *format, ...)
+{
+ va_list arglist;
+
+ va_start(arglist, format);
+
+ vprintf(format, arglist);
+}
+
+void Fail(char *format, ...)
+{
+ va_list arglist;
+
+ va_start(arglist, format);
+
+ vprintf(format, arglist);
+ printf("\n");
+
+ // This will exit the test process
+ PAL_TerminateEx(FAIL);
+}
+
+#ifdef PAL_PERF
+
+int __cdecl Test_Main(int argc, char **argv);
+int PAL_InitializeResult = 0;
+static const char PALTEST_LOOP_ENV[]="PALTEST_LOOP_COUNT";
+
+int __cdecl main(int argc, char **argv)
+{
+ int lastMainResult=0;
+
+ int loopCount=1; // default: run the test's main once
+ int loopIndex=0;
+ char *szPerfLoopEnv = NULL;
+
+ // Run PAL_Initialize once, save off the result. Any failures here
+ // will be detected later by calls to PAL_Initialize in the test's main.
+ PAL_InitializeResult = PAL_Initialize(argc, argv);
+
+ // Check the environment to see if we need to run the test's main
+ // multiple times. Ideally, we want to do this before PAL_Initialize so
+ // that the overhead of checking the environment is not included in the
+ // time between PAL_Initialize and PAL_Terminate. However, getenv in PAL
+ // can be run only after PAL_Initialize.
+ szPerfLoopEnv = getenv(PALTEST_LOOP_ENV);
+ if (szPerfLoopEnv != NULL)
+ {
+ loopCount = atoi(szPerfLoopEnv);
+ if (loopCount <= 0) loopCount = 1;
+ }
+
+ // call the test's actual main in a loop
+ for(loopIndex=0; loopIndex<loopCount; loopIndex++) {
+ lastMainResult = Test_Main(argc, argv);
+ }
+
+ // call PAL_Terminate for real
+ PAL_TerminateEx(lastMainResult);
+
+ return lastMainResult;
+}
+
+// Test's calls to PAL_Initialize and PAL_Terminate are redirected
+// to these bogus functions. These rely on PAL_Initialize and PAL_Terminate
+// being called by the 'main' above.
+#define PAL_Initialize(a, b) Bogus_PAL_Initialize(a, b)
+#define PAL_Terminate() Bogus_PAL_Terminate()
+int Bogus_PAL_Initialize(int argc, char* argv[])
+{
+ // PAL_Initialize has already been called by the real main.
+ // Just return the result.
+ return PAL_InitializeResult;
+}
+
+void Bogus_PAL_Terminate()
+{
+ // Don't call PAL_Terminate. It will be called later by the
+ // real main.
+ return;
+}
+
+// Rename the main provided by the test case
+#define main Test_Main
+
+#endif // PAL_PERF
+
+#ifdef BIGENDIAN
+inline ULONG VAL32(ULONG x)
+{
+ return( ((x & 0xFF000000L) >> 24) |
+ ((x & 0x00FF0000L) >> 8) |
+ ((x & 0x0000FF00L) << 8) |
+ ((x & 0x000000FFL) << 24) );
+}
+#define th_htons(w) (w)
+#else // BIGENDIAN
+#define VAL32(x) (x)
+#define th_htons(w) (((w) >> 8) | ((w) << 8))
+#endif // BIGENDIAN
+
+
+
+WCHAR* convert(char * aString)
+{
+ int size;
+ WCHAR* wideBuffer;
+
+ size = MultiByteToWideChar(CP_ACP,0,aString,-1,NULL,0);
+ wideBuffer = (WCHAR*) malloc(size*sizeof(WCHAR));
+ if (wideBuffer == NULL)
+ {
+ Fail("ERROR: Unable to allocate memory!\n");
+ }
+ MultiByteToWideChar(CP_ACP,0,aString,-1,wideBuffer,size);
+ return wideBuffer;
+}
+
+char* convertC(WCHAR * wString)
+{
+ int size;
+ char * MultiBuffer = NULL;
+
+ size = WideCharToMultiByte(CP_ACP,0,wString,-1,MultiBuffer,0,NULL,NULL);
+ MultiBuffer = (char*) malloc(size);
+ if (MultiBuffer == NULL)
+ {
+ Fail("ERROR: Unable to allocate memory!\n");
+ }
+ WideCharToMultiByte(CP_ACP,0,wString,-1,MultiBuffer,size,NULL,NULL);
+ return MultiBuffer;
+}
+
+#endif
+
+
+