Skip to content

Instantly share code, notes, and snippets.

@Xyene
Created July 1, 2016 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xyene/35c25dd2d90f62d244e1f4115e96eeb4 to your computer and use it in GitHub Desktop.
Save Xyene/35c25dd2d90f62d244e1f4115e96eeb4 to your computer and use it in GitHub Desktop.
WBox tests
import sys
import os
from dmoj.wbox.sandbox import WBoxPopen
def main():
dir = os.path.dirname(__file__)
print ' wbox Test Script'
print '====Please run as administrator==='
def run_file(file):
print 'Running', file
child = WBoxPopen(['python', os.path.join(dir, file)], 1, 16384, executable=sys.executable, network_block=True)
print 'Result:', child.communicate()
print 'Return:', child.returncode
print 'Execution time:', child.execution_time
print 'CPU time:', child.execution_time
print 'Memory usage: {:,d} bytes ({:.2f} MiB)'.format(child.max_memory_bytes, child.max_memory / 1024.)
print
run_file('hello.py')
run_file('hang.py')
run_file('memory_abuse.py')
run_file('google.py')
if __name__ == '__main__':
main()
import urllib2
file = urllib2.urlopen('http://www.google.com/')
try:
print file.read()
finally:
file.close()
#include <stdio.h>
int main() {
puts("Hello, World!");
}
print 'Hello, World!'
#include "user.h"
#include "process.h"
#include "firewall.h"
#include <shlwapi.h>
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <iostream>
int wmain() {
try {
UserManager user_manager;
JobbedProcessManager process;
WCHAR szDirectory[MAX_PATH], szExecutable[MAX_PATH];
GetModuleFileName(nullptr, szDirectory, MAX_PATH);
*(PathFindFileName(szDirectory) - 1) = '\0';
PathCombine(szExecutable, szDirectory, L"hello.exe");
NetworkManager network(L"wbox test", szExecutable);
process.time(2).memory(65536 * 1024).processes(1).command(L"hello.exe").directory(szDirectory)
.withLogin(user_manager.username(), user_manager.password()).executable(szExecutable);
process.spawn();
process.stdIn().close();
process.stdErr().close();
int ch, fd = _open_osfhandle((intptr_t) process.stdOut().detach(), _O_RDONLY);
FILE *file = _fdopen(fd, "r");
while ((ch = fgetc(file)) != EOF)
putchar(ch);
process.wait();
printf("Memory usage: %.2f MiB\n", process.memory() / 1024. / 1024.);
printf("Time usage: %.3fs\n", process.executionTime());
printf("Return: %lu\n", process.return_code());
} catch (WindowsException &e) {
std::cout << e.what() << '\n';
}
}
print ([0] * 10000000)[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment