parallelism 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*-perl-*-
  2. $description = "Test parallelism (-j) option.";
  3. $details = "This test creates a makefile with two double-colon default
  4. rules. The first rule has a series of sleep and echo commands
  5. intended to run in series. The second and third have just an
  6. echo statement. When make is called in this test, it is given
  7. the -j option with a value of 4. This tells make that it may
  8. start up to four jobs simultaneously. In this case, since the
  9. first command is a sleep command, the output of the second
  10. and third commands will appear before the first if indeed
  11. make is running all of these commands in parallel.";
  12. if (!$parallel_jobs) {
  13. return -1;
  14. }
  15. if ($vos) {
  16. $delete_command = "delete_file -no_ask";
  17. $sleep_command = "sleep -seconds";
  18. }
  19. else {
  20. $delete_command = "rm -f";
  21. $sleep_command = "sleep";
  22. }
  23. open(MAKEFILE,"> $makefile");
  24. print MAKEFILE <<"EOF";
  25. all : def_1 def_2 def_3
  26. def_1 : ; \@echo ONE; $sleep_command 3 ; echo TWO
  27. def_2 : ; \@$sleep_command 2 ; echo THREE
  28. def_3 : ; \@$sleep_command 1 ; echo FOUR
  29. EOF
  30. close(MAKEFILE);
  31. &run_make_with_options($makefile, "-j 4", &get_logfile);
  32. $answer = "ONE\nFOUR\nTHREE\nTWO\n";
  33. &compare_output($answer, &get_logfile(1));
  34. # Test parallelism with included files. Here we sleep/echo while
  35. # building the included files, to test that they are being built in
  36. # parallel.
  37. $makefile2 = &get_tmpfile;
  38. open(MAKEFILE,"> $makefile2");
  39. print MAKEFILE <<"EOF";
  40. all: 1 2; \@echo success
  41. -include 1.inc 2.inc
  42. 1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo "1: ; \@echo ONE; $sleep_command 2; echo TWO" > \$\@
  43. 2.inc: ; \@$sleep_command 1; echo THREE.inc; echo "2: ; \@$sleep_command 1; echo THREE" > \$\@
  44. EOF
  45. close(MAKEFILE);
  46. &run_make_with_options("$makefile2", "-j 4", &get_logfile);
  47. $answer = "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n";
  48. &compare_output($answer, &get_logfile(1));
  49. unlink('1.inc', '2.inc');
  50. # Test parallelism with included files--this time recurse first and make
  51. # sure the jobserver works.
  52. $makefile3 = &get_tmpfile;
  53. open(MAKEFILE,"> $makefile3");
  54. print MAKEFILE <<"EOF";
  55. recurse: ; \@\$(MAKE) --no-print-directory -f $makefile3 INC=yes all
  56. all: 1 2; \@echo success
  57. INC = no
  58. ifeq (\$(INC),yes)
  59. -include 1.inc 2.inc
  60. endif
  61. 1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo "1: ; \@echo ONE; $sleep_command 2; echo TWO" > \$\@
  62. 2.inc: ; \@$sleep_command 1; echo THREE.inc; echo "2: ; \@$sleep_command 1; echo THREE" > \$\@
  63. EOF
  64. close(MAKEFILE);
  65. &run_make_with_options("$makefile3", "-j 4", &get_logfile);
  66. $answer = "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n";
  67. &compare_output($answer, &get_logfile(1));
  68. unlink('1.inc', '2.inc');
  69. 1;