main.go 764 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "os/exec"
  6. "sync"
  7. )
  8. const (
  9. SYSCALL_NUMS = 400
  10. )
  11. func run(i int) {
  12. os.Setenv("DISABLE_SYSCALL", fmt.Sprintf("%d", i))
  13. _, err := exec.Command("node", "test.js").Output()
  14. if err != nil {
  15. fmt.Println(i)
  16. }
  17. }
  18. func main() {
  19. os.Chdir(".node_temp")
  20. // generate task list
  21. list := make([]int, SYSCALL_NUMS)
  22. for i := 0; i < SYSCALL_NUMS; i++ {
  23. list[i] = i
  24. }
  25. lock := sync.Mutex{}
  26. wg := sync.WaitGroup{}
  27. i := 0
  28. // run 4 tasks concurrently
  29. for j := 0; j < 4; j++ {
  30. wg.Add(1)
  31. go func() {
  32. defer wg.Done()
  33. for {
  34. lock.Lock()
  35. if i >= len(list) {
  36. lock.Unlock()
  37. return
  38. }
  39. task := list[i]
  40. i++
  41. lock.Unlock()
  42. run(task)
  43. }
  44. }()
  45. }
  46. // wait for all tasks to finish
  47. wg.Wait()
  48. }