Explorar el Código

Z991239-385 #comment LONG 类型在 Linux 下恢复回 32位,主要是有几个WINPR 中的测试案例不过

gifur hace 5 años
padre
commit
2a8c984353

+ 1 - 1
CMakeSettings.json

@@ -6,7 +6,7 @@
       "configurationType": "Debug",
       "buildRoot": "${projectDir}\\out\\build\\${name}",
       "installRoot": "${projectDir}\\out\\install\\${name}",
-      "cmakeCommandArgs": "-D BUILD_TESTING=ON",
+      "cmakeCommandArgs": "-D BUILD_TESTING=OFF",
       "buildCommandArgs": "",
       "ctestCommandArgs": "-C Debug",
       "inheritEnvironments": [ "msvc_x86" ],

+ 20 - 16
Common/SpHelper.h

@@ -1,5 +1,5 @@
-#ifndef __SP_SERVER_H
-#define __SP_SERVER_H
+#ifndef __SP_HELPER_H
+#define __SP_HELPER_H
 
 #pragma once
 #include "ErrorCode.h"
@@ -35,9 +35,8 @@ public:
 	SpBuffer & operator &(bool&);
 	SpBuffer & operator &(ULONGLONG&);
 	SpBuffer& operator &(LONGLONG&);
-	SpBuffer & operator &(LONG&);
-	SpBuffer & operator &(INT&);
 
+	SpBuffer & operator &(INT&);
 	SpBuffer & operator &(SHORT&);
 	SpBuffer & operator &(CHAR&);
 	SpBuffer & operator &(DWORD&);
@@ -52,7 +51,7 @@ public:
 	SpBuffer & operator &(CAutoArray<bool>&);
 	SpBuffer & operator &(CAutoArray<ULONGLONG>&);
 	SpBuffer & operator &(CAutoArray<LONGLONG>&);
-	SpBuffer & operator &(CAutoArray<LONG>&);
+	
 	SpBuffer & operator &(CAutoArray<INT>&);
 	
 	SpBuffer & operator &(CAutoArray<SHORT>&);
@@ -69,9 +68,8 @@ public:
 	SpBuffer & operator &(const bool&);
 	SpBuffer & operator &(const ULONGLONG&);
 	SpBuffer & operator &(const LONGLONG&);
-	SpBuffer & operator &(const LONG&);
+	
 	SpBuffer & operator &(const INT&);
-
 	SpBuffer & operator &(const SHORT&);
 	SpBuffer & operator &(const CHAR&);
 	SpBuffer & operator &(const DWORD&);
@@ -86,7 +84,6 @@ public:
 	SpBuffer & operator &(const CAutoArray<bool>&);
 	SpBuffer & operator &(const CAutoArray<ULONGLONG>&);
 	SpBuffer & operator &(const CAutoArray<LONGLONG>&);
-	SpBuffer & operator &(const CAutoArray<LONG>&);
 	SpBuffer & operator &(const CAutoArray<INT>&);
 	
 	SpBuffer & operator &(const CAutoArray<SHORT>&);
@@ -101,18 +98,22 @@ public:
 	SpBuffer & operator &(const CAutoArray<CBlob>&);
 
 #ifdef _WIN32
+	SpBuffer& operator &(LONG&);
+	SpBuffer& operator &(const LONG&);
+	SpBuffer& operator &(const CAutoArray<LONG>&);
+	SpBuffer& operator &(CAutoArray<LONG>&);
+
 	SpBuffer& operator &(UINT&);
 	SpBuffer& operator &(const UINT&);
 	SpBuffer& operator &(CAutoArray<UINT>&);
 	SpBuffer& operator &(const CAutoArray<UINT>&);
-#endif //_WIN32
 
-#if !defined(WIN32) && !defined(__i386__)
-	SpBuffer& operator &(ULONG&);
-	SpBuffer& operator &(CAutoArray<ULONG>&);
-	SpBuffer& operator &(const ULONG&);
-	SpBuffer& operator &(const CAutoArray<ULONG>&);
-#endif // !
+	//SpBuffer& operator &(ULONG&);
+	//SpBuffer& operator &(CAutoArray<ULONG>&);
+	//SpBuffer& operator &(const ULONG&);
+	//SpBuffer& operator &(const CAutoArray<ULONG>&);
+
+#endif //_WIN32
 
 	// use for write
 	CAutoBuffer ToBuffer();
@@ -353,4 +354,7 @@ do  {	\
 #define REQUIRE_FALSE(expr)	\
 	REQUIRE(!(expr))
 
-#endif // __SP_SERVER_H
+#define IS_SUCCEED(hr)	((hr) == Error_Succeed)
+#define IS_FAILURED(hr) (!(IS_SUCCEED(hr)))
+
+#endif // __SP_HELPER_H

+ 3 - 3
libtoolkit/test/test_process.cpp

@@ -45,7 +45,7 @@ static int create_process_test(tk_process_t* new_process)
 	 * The lpApplicationName parameter can be NULL. In that case, 
 	 * the module name must be the first white space¨Cdelimited token in the lpCommandLine string. 
 	 */
-	auto ret = CreateProcessA(module_name, NULL,
+	auto ret = CreateProcessA(NULL, module_name,
 		NULL, NULL, FALSE, 0, 
 		NULL, NULL, &si, &pi);
 	if (ret) {
@@ -118,9 +118,9 @@ TEST(TestProcessMonitor, TestProcess)
 	ASSERT_TRUE(process_monitor_start(pm) == 0);
 	/**/
 	for (int i = 0; i < process_create_max_count; ++i) {
-		std::cout << "create test process[" << i << "]" << std::endl;
+		std::cout << "create test process[" << i << "]..." << std::endl;
 		tk_process_t process;
-		EXPECT_TRUE(create_process_test(&process) == 0);
+		ASSERT_TRUE(create_process_test(&process) == 0);
 		EXPECT_TRUE(0 == process_monitor_add(pm, &process));
 	}
 	const int elapse_sec = 1;

+ 1 - 1
module/mod_sample/SampleFSM.cpp

@@ -52,7 +52,7 @@ void CSampleFSM::SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionCon
 
 void CSampleFSM::s0_on_entry()
 {
-	//ScheduleTimer(TIMER_LOG_SEND_ID, TIMER_LOG_SEND_INTERVAL);
+	ScheduleTimer(TIMER_LOG_SEND_ID, TIMER_LOG_SEND_INTERVAL);
 }
 
 void CSampleFSM::s0_on_exit()

+ 6 - 3
module/mod_testPassiveEntity/mod_testPassiveEntity.cpp

@@ -14,10 +14,13 @@ public:
 	void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
 	{
 		LOG_FUNCTION();
-		for (int i = 0; i < strArgs.GetCount(); ++i) {
-			Dbg("args[%d]: %s", i, strArgs[i]);
+		auto result = __onTest(strArgs);
+		if (IS_FAILURED(result)) {
+			for (int i = 0; i < strArgs.GetCount(); ++i) {
+				Dbg("args[%d]: %s", i, strArgs[i].GetData());
+			}
 		}
-		pTransactionContext->SendAnswer(__onTest(strArgs));
+		pTransactionContext->SendAnswer(result);
 	}
 	void OnStarted()
 	{

+ 30 - 31
spbase/SpHelper.cpp

@@ -273,12 +273,6 @@ SpBuffer & SpBuffer::operator &(LONGLONG &v)
 	return *this;
 }
 
-SpBuffer & SpBuffer::operator &(LONG &v)
-{
-	DoT(m_pInternalBuf, m_iMode, v);
-	return *this;
-}
-
 SpBuffer & SpBuffer::operator &(INT &v)
 {
 	DoT(m_pInternalBuf, m_iMode, v);
@@ -366,12 +360,6 @@ SpBuffer & SpBuffer::operator &(CAutoArray<LONGLONG> &v)
 	return *this;
 }
 
-SpBuffer & SpBuffer::operator &(CAutoArray<LONG> &v)
-{
-	DoArrayT(m_pInternalBuf, m_iMode, v);
-	return *this;
-}
-
 SpBuffer & SpBuffer::operator &(CAutoArray<INT> &v)
 {
 	DoArrayT(m_pInternalBuf, m_iMode, v);
@@ -454,11 +442,6 @@ SpBuffer & SpBuffer::operator &(const LONGLONG&v)
 	return *this;
 }
 
-SpBuffer & SpBuffer::operator &(const LONG&v)
-{
-	WriteT(m_pInternalBuf, v);
-	return *this;
-}
 SpBuffer & SpBuffer::operator &(const INT&v)
 {
 	WriteT(m_pInternalBuf, v);
@@ -537,12 +520,6 @@ SpBuffer & SpBuffer::operator &(const CAutoArray<LONGLONG> &v)
 	return *this;
 }
 
-SpBuffer & SpBuffer::operator &(const CAutoArray<LONG> &v)
-{
-	WriteArrayT(m_pInternalBuf, v);
-	return *this;
-}
-
 SpBuffer & SpBuffer::operator &(const CAutoArray<INT> &v)
 {
 	WriteArrayT(m_pInternalBuf, v);
@@ -636,30 +613,52 @@ SpBuffer& SpBuffer::operator &(const CAutoArray<UINT>& v)
 	return *this;
 }
 
-#endif //_WIN32
-
-#if !defined(WIN32) && !defined(__i386__)
-SpBuffer& SpBuffer::operator &(ULONG& v)
+SpBuffer& SpBuffer::operator &(LONG& v)
 {
 	DoT(m_pInternalBuf, m_iMode, v);
 	return *this;
 }
-SpBuffer& SpBuffer::operator &(CAutoArray<ULONG>& v)
+
+SpBuffer& SpBuffer::operator &(CAutoArray<LONG>& v)
 {
 	DoArrayT(m_pInternalBuf, m_iMode, v);
 	return *this;
 }
-SpBuffer& SpBuffer::operator &(const ULONG& v)
+
+SpBuffer& SpBuffer::operator &(const LONG& v)
 {
 	WriteT(m_pInternalBuf, v);
 	return *this;
 }
-SpBuffer& SpBuffer::operator &(const CAutoArray<ULONG>& v)
+
+SpBuffer& SpBuffer::operator &(const CAutoArray<LONG>& v)
 {
 	WriteArrayT(m_pInternalBuf, v);
 	return *this;
 }
-#endif
+
+//SpBuffer& SpBuffer::operator &(ULONG& v)
+//{
+//	DoT(m_pInternalBuf, m_iMode, v);
+//	return *this;
+//}
+//SpBuffer& SpBuffer::operator &(CAutoArray<ULONG>& v)
+//{
+//	DoArrayT(m_pInternalBuf, m_iMode, v);
+//	return *this;
+//}
+//SpBuffer& SpBuffer::operator &(const ULONG& v)
+//{
+//	WriteT(m_pInternalBuf, v);
+//	return *this;
+//}
+//SpBuffer& SpBuffer::operator &(const CAutoArray<ULONG>& v)
+//{
+//	WriteArrayT(m_pInternalBuf, v);
+//	return *this;
+//}
+
+#endif //_WIN32
 
 CAutoBuffer SpBuffer::ToBuffer()
 {

+ 4 - 3
spbase/sp_cfg.cpp

@@ -172,8 +172,9 @@ static sp_cfg_shell_module_t* find_module(sp_cfg_shell_ini_t *shell, const char
 {
 	int i;
 	sp_cfg_shell_module_t* mod;
+	const int len = (strstr(mod_name, "lib") == mod_name) ? 3 : 0; //linux .so name
 	ARRAY_FOR_EACH_ENTRY(mod, i, shell->arr_module, sp_cfg_shell_module_t*) {
-		if (_stricmp(mod->name, mod_name) == 0)
+		if (_stricmp(mod->name, mod_name + len) == 0)
 			return mod;
 	}
 	return NULL;
@@ -625,13 +626,13 @@ static int load_shell_ini(sp_dir_t *dir, sp_cfg_shell_ini_t *shell, sp_cfg_root_
 			if (ret == 3) {
 				sp_cfg_shell_module_t *mod;
 				if (str_has_suffix(tmp, MOD_LIB_SUFFIX)) {
-					int len = strlen(tmp);
+					const int len = strlen(tmp);
 					tmp[len-strlen(MOD_LIB_SUFFIX)] = 0;
 				}
 				mod = find_module(shell, tmp);
 				if (!mod) {
 					char sal_tmp[MAX_PATH];
-					int len = (strstr(tmp, "lib") == tmp) ? 3 : 0;
+					const int len = (strstr(tmp, "lib") == tmp) ? 3 : 0;
 					mod = (sp_cfg_shell_module_t *)shm_malloc(sizeof(sp_cfg_shell_module_t));
 					memset(mod, 0, sizeof(sp_cfg_shell_module_t));
 					mod->name = shm_strdup(tmp + len);

+ 8 - 2
winpr/include/winpr/wtypes.h.in

@@ -208,7 +208,10 @@ typedef __uint16 WCHAR;
 typedef WCHAR UNICODE, *PWCHAR, *LPWCH, *PWCH, *BSTR, *LMSTR, *LPWSTR, *PWSTR;
 typedef const WCHAR* LPCWCH, *PCWCH, *LMCSTR, *LPCWSTR, *PCWSTR;
 
-#if 0
+/*At WindowsX64 platform, sizeof(long) or sizeof(LONG) still 32bit bcz they applies LLP64 digest model
+ *whereas At other platform like Unix, they applies LP64 model.
+ */
+#if 1
 
 typedef __int16 SHORT, *PSHORT;
 typedef __int32 INT, *PINT, *LPINT;
@@ -220,6 +223,8 @@ typedef __uint16 USHORT, *PUSHORT;
 typedef __uint32 ULONG, *PULONG;
 typedef __uint64 ULONGLONG, *PULONGLONG;
 
+typedef LONG HRESULT;
+
 #else
 
 typedef short SHORT, * PSHORT;
@@ -232,6 +237,8 @@ typedef unsigned short USHORT, * PUSHORT;
 typedef unsigned long ULONG, * PULONG;
 typedef unsigned long long ULONGLONG, * PULONGLONG;
 
+typedef __int32 HRESULT;
+
 #endif
 
 
@@ -288,7 +295,6 @@ typedef HANDLE HMENU;
 typedef DWORD HCALL;
 
 typedef ULONG error_status_t;
-typedef LONG HRESULT;
 typedef LONG SCODE;
 typedef SCODE* PSCODE;
 

+ 1 - 1
winpr/libwinpr/crt/test/CMakeLists.txt

@@ -5,7 +5,7 @@ set(MODULE_PREFIX "TEST_CRT")
 set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
 
 set(${MODULE_PREFIX}_TESTS
-	TestTypes.c
+	TestTypeSizes.c
 	TestFormatSpecifiers.c
 	TestAlignment.c
 	TestString.c

+ 2 - 2
winpr/libwinpr/crt/test/TestTypes.c → winpr/libwinpr/crt/test/TestTypeSizes.c

@@ -22,7 +22,7 @@
 #define EXPECTED_SIZEOF_UINT32 4
 #define EXPECTED_SIZEOF_DWORD 4
 #define EXPECTED_SIZEOF_DWORD32 4
-#define EXPECTED_SIZEOF_LONG 4
+#define EXPECTED_SIZEOF_LONG 4 //at win platform, we use 32bit
 #define EXPECTED_SIZEOF_LONG32 4
 #define EXPECTED_SIZEOF_INT64 8
 #define EXPECTED_SIZEOF_UINT64 8
@@ -51,7 +51,7 @@
 		status = -1;                                                                               \
 	}
 
-int TestTypes(int argc, char* argv[])
+int TestTypeSizes(int argc, char* argv[])
 {
 	int status = 0;
 

+ 13 - 5
winpr/libwinpr/synch/test/TestSynchBarrier.c

@@ -27,10 +27,10 @@ static DWORD WINAPI test_synch_barrier_thread(LPVOID lpParam)
 	BOOL status = FALSE;
 	struct test_params* p = (struct test_params*)lpParam;
 	DWORD i;
-
+	const ULONG currentNum = p->threadCount + 1;
 	InterlockedIncrement(&p->threadCount);
 
-	// printf("Thread #%03u entered.\n", tnum);
+	printf("Thread #%03u entered.\n", currentNum);
 
 	/* wait for start event from main */
 	if (WaitForSingleObject(gStartEvent, INFINITE) != WAIT_OBJECT_0)
@@ -39,7 +39,7 @@ static DWORD WINAPI test_synch_barrier_thread(LPVOID lpParam)
 		goto out;
 	}
 
-	// printf("Thread #%03u unblocked.\n", tnum);
+	printf("Thread #%03u unblocked.\n", currentNum);
 
 	for (i = 0; i < p->loops && gErrorCount == 0; i++)
 	{
@@ -47,7 +47,7 @@ static DWORD WINAPI test_synch_barrier_thread(LPVOID lpParam)
 		Sleep(rand() % MAX_SLEEP_MS);
 		status = EnterSynchronizationBarrier(&gBarrier, p->flags);
 
-		// printf("Thread #%03u status: %s\n", tnum, status ? "TRUE" : "FALSE");
+		printf("Thread #%03u status: %s\n", currentNum, status ? "TRUE" : "FALSE");
 		if (status)
 			InterlockedIncrement(&p->trueCount);
 		else
@@ -55,7 +55,7 @@ static DWORD WINAPI test_synch_barrier_thread(LPVOID lpParam)
 	}
 
 out:
-	// printf("Thread #%03u leaving.\n", tnum);
+	printf("Thread #%03u leaving.\n", currentNum);
 	return 0;
 }
 
@@ -121,6 +121,7 @@ static BOOL TestSynchBarrierWithFlags(DWORD dwFlags, DWORD dwThreads, DWORD dwLo
 
 		while (i--)
 		{
+			printf("%s: WaitForSingleObject(thread[%" PRIu32 "])...\n", __FUNCTION__, i);
 			if (WAIT_OBJECT_0 != (dwStatus = WaitForSingleObject(threads[i], INFINITE)))
 			{
 				printf("%s: WaitForSingleObject(thread[%" PRIu32 "] unexpectedly returned %" PRIu32
@@ -198,6 +199,7 @@ int TestSynchBarrier(int argc, char* argv[])
 		    __FUNCTION__);
 		return -1;
 	}
+	printf("%s: InitializeSynchronizationBarrier succeeded with lTotalThreads = 0\n",__FUNCTION__);
 
 	if (InitializeSynchronizationBarrier(&gBarrier, -1, -1))
 	{
@@ -206,6 +208,8 @@ int TestSynchBarrier(int argc, char* argv[])
 		    __FUNCTION__);
 		return -1;
 	}
+	printf("%s: InitializeSynchronizationBarrier succeeded with lTotalThreads = -1\n",__FUNCTION__);
+
 
 	if (InitializeSynchronizationBarrier(&gBarrier, 1, -2))
 	{
@@ -213,16 +217,20 @@ int TestSynchBarrier(int argc, char* argv[])
 		       __FUNCTION__);
 		return -1;
 	}
+	printf("%s: InitializeSynchronizationBarrier succeeded with lSpinCount = -2\n", __FUNCTION__);
 
 	/* Functional tests */
 
+	printf("%s: test TestSynchBarrierWithFlags\n", __FUNCTION__);
 	if (!TestSynchBarrierWithFlags(0, dwMaxThreads, dwNumLoops))
 		return -1;
 
+	printf("%s: test TestSynchBarrierWithFlags with SYNCHRONIZATION_BARRIER_FLAGS_SPIN_ONLY\n", __FUNCTION__);
 	if (!TestSynchBarrierWithFlags(SYNCHRONIZATION_BARRIER_FLAGS_SPIN_ONLY, dwMinThreads,
 	                               dwNumLoops))
 		return -1;
 
+	printf("%s: test TestSynchBarrierWithFlags with SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY\n", __FUNCTION__);
 	if (!TestSynchBarrierWithFlags(SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY, dwMaxThreads,
 	                               dwNumLoops))
 		return -1;

+ 2 - 5
winpr/libwinpr/thread/test/TestThreadCreateProcess.c

@@ -62,7 +62,7 @@ int TestProcessWaitTimeout(LPTSTR lpCommandLine)
 		printf("Failed to wait process timeout\n");
 		return 1;
 	}
-
+	
 	exitCode = 0;
 	status = GetExitCodeProcess(ProcessInformation.hProcess, &exitCode);
 
@@ -72,7 +72,7 @@ int TestProcessWaitTimeout(LPTSTR lpCommandLine)
 	CloseHandle(ProcessInformation.hProcess);
 	CloseHandle(ProcessInformation.hThread);
 	FreeEnvironmentStrings(lpszEnvironmentBlock);
-	return 1;
+	return 0;
 }
 
 int TestCreateProcess(LPTSTR lpCommandLine)
@@ -217,9 +217,6 @@ int TestCreateProcess(LPTSTR lpCommandLine)
 	return ret;
 }
 
-
-
-
 int TestThreadCreateProcess(int argc, char* argv[])
 {
 	CHAR lpCommandLine[256] = {'\0'};

+ 4 - 4
winpr/libwinpr/thread/test/TestThreadGetHandle.c

@@ -36,23 +36,23 @@ int TestThreadGetHandle(int argc, char* argv[])
     }
 
     if(threadID == 0) {
-        fprintf(stderr, "thread id is invalid after created.");
+        fprintf(stderr, "thread id is invalid after created.\n");
         return -1;
     }
 
     waitResult = WaitForSingleObject(thread, 1000);
     if (waitResult != WAIT_TIMEOUT) {
-            fprintf(stderr, "wait thread should be timeout!");
+            fprintf(stderr, "wait thread should be timeout!\n");
             return -1;
     }
 
     if(g_new_thread_id != threadID) {
-        fprintf(stderr,  "global thread id %d does not equals with returned thread id %d", g_new_thread_id, threadID);
+        fprintf(stderr,  "global thread id %u does not equals with returned thread id %u\n", g_new_thread_id, threadID);
         return -1;
     }
     openThread = OpenThread(THREAD_ALL_ACCESS, FALSE, threadID);
     if(NULL == openThread) {
-        fprintf(stderr, "open thread and get handle is null!");
+        fprintf(stderr, "open thread and get handle is null!\n");
         return -1;
     }
     return 0;

+ 11 - 2
winpr/libwinpr/thread/thread.c

@@ -288,9 +288,16 @@ static BOOL reset_event(WINPR_THREAD* thread)
 
 static BOOL thread_compare(const void* a, const void* b)
 {
+	/*see GetCurrentThreadId's comment*/
+#if 1
+	const DWORD pa = *(DWORD*)a;
+	const DWORD pb = *(DWORD*)b;
+	BOOL rc = pa == pb ? TRUE : FALSE;
+#else
 	const pthread_t* p1 = a;
 	const pthread_t* p2 = b;
 	BOOL rc = pthread_equal(*p1, *p2);
+#endif
 	return rc;
 }
 
@@ -512,7 +519,9 @@ HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize
 		if (!set_event(thread))
 			goto error_thread_list;
 	}
-
+	if (lpThreadId) {
+		*lpThreadId = thread->thread;
+	}
 	return handle;
 error_thread_list:
 	pthread_cond_destroy(&thread->threadIsReady);
@@ -703,7 +712,7 @@ HANDLE _GetCurrentThread(VOID)
 
 DWORD GetCurrentThreadId(VOID)
 {
-#if defined(__linux__)
+#if 0//defined(__linux__) //need to estimate other effect.
 	return (size_t)syscall(SYS_gettid);
 #else
 	pthread_t tid;