1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

ST: Support Cygwin64 and MIPS

This commit is contained in:
winlin 2021-10-02 08:54:53 +08:00
parent 7d3ec991e1
commit 1836847269
29 changed files with 1116 additions and 105 deletions

View file

@ -1,25 +1,5 @@
/*
The MIT License (MIT)
Copyright (c) 2021 Winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2021 Winlin */
#include <st_utest.hpp>
@ -30,8 +10,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copy from gtest-1.6.0/src/gtest_main.cc
GTEST_API_ int main(int argc, char **argv) {
// Select the best event system available on the OS. In Linux this is
// epoll(). On BSD it will be kqueue.
// epoll(). On BSD it will be kqueue. On Cygwin it will be select.
#if __CYGWIN__
assert(st_set_eventsys(ST_EVENTSYS_SELECT) != -1);
#else
assert(st_set_eventsys(ST_EVENTSYS_ALT) != -1);
#endif
// Initialize state-threads, create idle coroutine.
assert(st_init() == 0);
testing::InitGoogleTest(&argc, argv);
@ -47,3 +33,107 @@ VOID TEST(SampleTest, FastSampleInt64Test)
EXPECT_EQ(8, (int)sizeof(int64_t));
}
void* pfn_coroutine(void* /*arg*/)
{
st_usleep(0);
return NULL;
}
VOID TEST(SampleTest, StartCoroutine)
{
st_thread_t trd = st_thread_create(pfn_coroutine, NULL, 1, 0);
EXPECT_TRUE(trd != NULL);
// Wait for joinable coroutine to quit.
st_thread_join(trd, NULL);
}
VOID TEST(SampleTest, StartCoroutineX3)
{
st_thread_t trd0 = st_thread_create(pfn_coroutine, NULL, 1, 0);
st_thread_t trd1 = st_thread_create(pfn_coroutine, NULL, 1, 0);
st_thread_t trd2 = st_thread_create(pfn_coroutine, NULL, 1, 0);
EXPECT_TRUE(trd0 != NULL && trd1 != NULL && trd2 != NULL);
// Wait for joinable coroutine to quit.
st_thread_join(trd1, NULL);
st_thread_join(trd2, NULL);
st_thread_join(trd0, NULL);
}
void* pfn_coroutine_add(void* arg)
{
int v = 0;
int* pi = (int*)arg;
// Load the change of arg.
while (v != *pi) {
v = *pi;
st_usleep(0);
}
// Add with const.
v += 100;
*pi = v;
return NULL;
}
VOID TEST(SampleTest, StartCoroutineAdd)
{
int v = 0;
st_thread_t trd = st_thread_create(pfn_coroutine_add, &v, 1, 0);
EXPECT_TRUE(trd != NULL);
// Wait for joinable coroutine to quit.
st_thread_join(trd, NULL);
EXPECT_EQ(100, v);
}
VOID TEST(SampleTest, StartCoroutineAddX3)
{
int v = 0;
st_thread_t trd0 = st_thread_create(pfn_coroutine_add, &v, 1, 0);
st_thread_t trd1 = st_thread_create(pfn_coroutine_add, &v, 1, 0);
st_thread_t trd2 = st_thread_create(pfn_coroutine_add, &v, 1, 0);
EXPECT_TRUE(trd0 != NULL && trd1 != NULL && trd2 != NULL);
// Wait for joinable coroutine to quit.
st_thread_join(trd0, NULL);
st_thread_join(trd1, NULL);
st_thread_join(trd2, NULL);
EXPECT_EQ(300, v);
}
int pfn_coroutine_params_x4(int a, int b, int c, int d)
{
int e = 0;
st_usleep(0);
e += a + b + c + d;
e += 100;
return e;
}
void* pfn_coroutine_params(void* arg)
{
int r0 = pfn_coroutine_params_x4(1, 2, 3, 4);
*(int*)arg = r0;
return NULL;
}
VOID TEST(SampleTest, StartCoroutineParams)
{
int r0 = 0;
st_thread_t trd = st_thread_create(pfn_coroutine_params, &r0, 1, 0);
EXPECT_TRUE(trd != NULL);
// Wait for joinable coroutine to quit.
st_thread_join(trd, NULL);
EXPECT_EQ(110, r0);
}