Skip to content

Commit

Permalink
Merge pull request #38 from jamesmoriarty/bugfix/make-tests-reliable
Browse files Browse the repository at this point in the history
refinement: try pure c stub process.
  • Loading branch information
jamesmoriarty authored Jun 12, 2021
2 parents ef22e2f + af393f0 commit 5c44769
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 62 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ csgo.exe*
client.*
!client.go
!client.def
cover.out
# go test -covermode=atomic -coverprofile=cover -v ./...
cover.*
# go tool cover -html=cover.out -o cover.html
cover.html
18 changes: 7 additions & 11 deletions bin/build.bat
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
go version

set PATH=%PATH%;C:\MinGW\bin

REM bug - issues with mingw 64bit support.^
REM configure csgo.exe dist is 386^
set GOARCH=386
set GOOS=windows
set CGO_ENABLED=1
set PATH=%PATH%;C:\MinGW\bin

REM build .\test\dll\csgo.exe^
cd .\test\dll
go build -buildmode=c-archive -o client.a client.go
gcc -shared -pthread -o client.dll client.a -lWinMM -lntdll -lWS2_32
gcc client.def client.a -shared -lwinmm -lWs2_32 -o client.dll -Wl,--out-implib,client.lib
go build -v -o csgo.exe main.go
gcc -c -o client.o client.c
gcc -o client.dll -s -shared client.o -Wl,--subsystem,windows
gcc -o csgo csgo.c -L. -lclient
cd ..\..

REM build .\test\nodll\csgo.exe^
Expand All @@ -30,7 +28,5 @@ go build -v -ldflags "-X github.com/jamesmoriarty/gohack.Version=%VERSION% -X gi

if %errorlevel% neq 0 exit /b %errorlevel%

REM bug - issues with gc + syscalls + including windows golang dll + exe.^
go test -v -coverprofile cover.out

exit 0
REM test^
go test -covermode=atomic -coverprofile='cover.out' -v ./...
3 changes: 3 additions & 0 deletions gohack_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os/exec"
"strings"
"testing"
"time"
)

func withProcess(path string, f func()) {
Expand All @@ -20,6 +21,8 @@ func withProcess(path string, f func()) {

defer exec.Command("TASKKILL", "/F", "/IM", exe).Run()

time.Sleep(1 * time.Second)

f()
}

Expand Down
9 changes: 9 additions & 0 deletions test/dll/client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>
#include "windows.h"
#include "client.h"

EXPORT void HelloWorld(){
Sleep(1316134911);

printf("Hello World");
}
3 changes: 0 additions & 3 deletions test/dll/client.def

This file was deleted.

20 changes: 0 additions & 20 deletions test/dll/client.go

This file was deleted.

3 changes: 3 additions & 0 deletions test/dll/client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define EXPORT __declspec(dllexport)

EXPORT void HelloWorld (void);
6 changes: 6 additions & 0 deletions test/dll/csgo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "client.h"

int main(){
HelloWorld();
return 0;
}
3 changes: 0 additions & 3 deletions test/dll/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions test/dll/go.sum

This file was deleted.

22 changes: 0 additions & 22 deletions test/dll/main.go

This file was deleted.

0 comments on commit 5c44769

Please sign in to comment.