windows tests
This commit is contained in:
parent
686a2ab92c
commit
f04b4a1f68
8 changed files with 40 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -43,3 +43,4 @@ src/-lstdc++.res
|
||||||
# Neural network for the NNUE evaluation
|
# Neural network for the NNUE evaluation
|
||||||
**/*.nnue
|
**/*.nnue
|
||||||
|
|
||||||
|
/.vs
|
|
@ -73,6 +73,7 @@ class Stockfish {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError: (error) {
|
onError: (error) {
|
||||||
|
print('The init isolate encountered an error $error');
|
||||||
developer.log('The init isolate encountered an error $error',
|
developer.log('The init isolate encountered an error $error',
|
||||||
name: 'Stockfish');
|
name: 'Stockfish');
|
||||||
_cleanUp(1);
|
_cleanUp(1);
|
||||||
|
@ -108,6 +109,8 @@ class Stockfish {
|
||||||
throw StateError('Stockfish is not ready ($stateValue)');
|
throw StateError('Stockfish is not ready ($stateValue)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("sending: " + line);
|
||||||
|
|
||||||
final unicodePointer = '$line\n'.toNativeUtf8();
|
final unicodePointer = '$line\n'.toNativeUtf8();
|
||||||
final pointer = unicodePointer.cast<Char>();
|
final pointer = unicodePointer.cast<Char>();
|
||||||
_bindings.stockfish_stdin_write(pointer);
|
_bindings.stockfish_stdin_write(pointer);
|
||||||
|
@ -210,6 +213,7 @@ Future<bool> _spawnIsolates(List<SendPort> mainAndStdout) async {
|
||||||
try {
|
try {
|
||||||
await Isolate.spawn(_isolateStdout, mainAndStdout[1]);
|
await Isolate.spawn(_isolateStdout, mainAndStdout[1]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
print('Failed to spawn stdout isolate: $error');
|
||||||
developer.log('Failed to spawn stdout isolate: $error', name: 'Stockfish');
|
developer.log('Failed to spawn stdout isolate: $error', name: 'Stockfish');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -217,6 +221,7 @@ Future<bool> _spawnIsolates(List<SendPort> mainAndStdout) async {
|
||||||
try {
|
try {
|
||||||
await Isolate.spawn(_isolateMain, mainAndStdout[0]);
|
await Isolate.spawn(_isolateMain, mainAndStdout[0]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
print('Failed to spawn stdout isolate: $error');
|
||||||
developer.log('Failed to spawn main isolate: $error', name: 'Stockfish');
|
developer.log('Failed to spawn main isolate: $error', name: 'Stockfish');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.18)
|
||||||
project(flutter_stockfish_plugin VERSION 0.0.1 LANGUAGES CXX)
|
project(flutter_stockfish_plugin VERSION 0.0.1 LANGUAGES CXX)
|
||||||
file(GLOB_RECURSE cppPaths "Stockfish/src/*.cpp")
|
file(GLOB_RECURSE cppPaths "Stockfish/src/*.cpp")
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -flto")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3 -flto") #-DNDEBUG -fno-exceptions -funroll-loops
|
||||||
set(NNUE_NAME nn-5af11540bbfe.nnue)
|
set(NNUE_NAME nn-5af11540bbfe.nnue)
|
||||||
|
|
||||||
add_library(flutter_stockfish_plugin SHARED
|
add_library(flutter_stockfish_plugin SHARED
|
||||||
|
|
|
@ -105,7 +105,7 @@ struct Tie: public streambuf { // MSVC requires split streambuf for cin and cout
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
|
|
||||||
Logger() : in(cin.rdbuf(), file.rdbuf()), out(cout.rdbuf(), file.rdbuf()) {}
|
Logger() : in(fakein.rdbuf(), file.rdbuf()), out(fakeout.rdbuf(), file.rdbuf()) {}
|
||||||
~Logger() { start(""); }
|
~Logger() { start(""); }
|
||||||
|
|
||||||
ofstream file;
|
ofstream file;
|
||||||
|
@ -118,8 +118,8 @@ public:
|
||||||
|
|
||||||
if (l.file.is_open())
|
if (l.file.is_open())
|
||||||
{
|
{
|
||||||
cout.rdbuf(l.out.buf);
|
fakeout.rdbuf(l.out.buf);
|
||||||
cin.rdbuf(l.in.buf);
|
fakein.rdbuf(l.in.buf);
|
||||||
l.file.close();
|
l.file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,8 +133,8 @@ public:
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
cin.rdbuf(&l.in);
|
fakein.rdbuf(&l.in);
|
||||||
cout.rdbuf(&l.out);
|
fakeout.rdbuf(&l.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -753,10 +753,14 @@ void init([[maybe_unused]] int argc, char* argv[]) {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// Under windows argv[0] may not have the extension. Also _get_pgmptr() had
|
// Under windows argv[0] may not have the extension. Also _get_pgmptr() had
|
||||||
// issues in some windows 10 versions, so check returned values carefully.
|
// issues in some windows 10 versions, so check returned values carefully.
|
||||||
char* pgmptr = nullptr;
|
wchar_t buffer[MAX_PATH];
|
||||||
if (!_get_pgmptr(&pgmptr) && pgmptr != nullptr && *pgmptr)
|
if (GetModuleFileNameW(nullptr, buffer, MAX_PATH) != 0)
|
||||||
argv0 = pgmptr;
|
{
|
||||||
#endif
|
char narrowBuffer[MAX_PATH];
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, narrowBuffer, MAX_PATH, NULL, NULL);
|
||||||
|
argv0 = narrowBuffer;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
pathSeparator = "/";
|
pathSeparator = "/";
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -70,7 +70,6 @@ std::ostream& operator<<(std::ostream&, SyncCout);
|
||||||
#define sync_cout fakeout << IO_LOCK
|
#define sync_cout fakeout << IO_LOCK
|
||||||
#define sync_endl fakeendl << IO_UNLOCK
|
#define sync_endl fakeendl << IO_UNLOCK
|
||||||
|
|
||||||
|
|
||||||
// align_ptr_up() : get the first aligned element of an array.
|
// align_ptr_up() : get the first aligned element of an array.
|
||||||
// ptr must point to an array of size at least `sizeof(T) * N + alignment` bytes,
|
// ptr must point to an array of size at least `sizeof(T) * N + alignment` bytes,
|
||||||
// where N is the number of elements in the array.
|
// where N is the number of elements in the array.
|
||||||
|
|
|
@ -33,7 +33,7 @@ int stockfish_main() {
|
||||||
char *argv[] = {(char *)""};
|
char *argv[] = {(char *)""};
|
||||||
int exitCode = main(argc, argv);
|
int exitCode = main(argc, argv);
|
||||||
|
|
||||||
fakeout << QUITOK << "\n";
|
fakeout << exitCode << "\n";
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
Sleep(100);
|
Sleep(100);
|
||||||
|
@ -49,6 +49,7 @@ int stockfish_main() {
|
||||||
|
|
||||||
ssize_t stockfish_stdin_write(char *data) {
|
ssize_t stockfish_stdin_write(char *data) {
|
||||||
std::string val(data);
|
std::string val(data);
|
||||||
|
fakeout << val << fakeendl;
|
||||||
fakein << val << fakeendl;
|
fakein << val << fakeendl;
|
||||||
return val.length();
|
return val.length();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "stream_fix.h"
|
#include "stream_fix.h"
|
||||||
|
|
||||||
bool FakeStream::try_get_line(std::string& val) {
|
bool FakeStream::try_get_line(std::string &val)
|
||||||
|
{
|
||||||
std::unique_lock<std::mutex> lock(mutex_guard);
|
std::unique_lock<std::mutex> lock(mutex_guard);
|
||||||
if (string_queue.empty() || closed) return false;
|
if (string_queue.empty() || closed) return false;
|
||||||
val = string_queue.front();
|
val = string_queue.front();
|
||||||
|
@ -26,6 +27,17 @@ bool std::getline(FakeStream& is, std::string& str) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*FakeStream &operator<<(FakeStream &os, SyncFakeout sc) {
|
||||||
|
static std::mutex m;
|
||||||
|
if (sc == SyncFakeout::IO_LOCK)
|
||||||
|
m.lock();
|
||||||
|
|
||||||
|
if (sc == SyncFakeout::IO_UNLOCK)
|
||||||
|
m.unlock();
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}*/
|
||||||
|
|
||||||
FakeStream fakeout;
|
FakeStream fakeout;
|
||||||
FakeStream fakein;
|
FakeStream fakein;
|
||||||
std::string fakeendl("\n");
|
std::string fakeendl("\n");
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline std::string stringify(const T& input) {
|
inline std::string stringify(const T& input) {
|
||||||
std::ostringstream output; // from www .ja va 2s . com
|
std::ostringstream output;
|
||||||
output << input;
|
output << input;
|
||||||
return output.str();
|
return output.str();
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,9 @@ namespace std {
|
||||||
bool getline(FakeStream& is, std::string& str);
|
bool getline(FakeStream& is, std::string& str);
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
|
//enum SyncFakeout { IO_LOCK, IO_UNLOCK };
|
||||||
|
//FakeStream &operator<<(FakeStream &os, SyncFakeout sc);
|
||||||
|
|
||||||
// #define endl fakeendl
|
// #define endl fakeendl
|
||||||
// #define cout fakeout
|
// #define cout fakeout
|
||||||
// #define cin fakein
|
// #define cin fakein
|
||||||
|
|
Loading…
Reference in a new issue