<commit_before>import ./make-test.nix ({ pkgs, ...} :

let

  # Build Quake with coverage instrumentation.
  overrides = pkgs:
    {
      quake3game = pkgs.quake3game.override (args: {
        stdenv = pkgs.stdenvAdapters.addCoverageInstrumentation args.stdenv;
      });
    };

  # Only allow the demo data to be used (only if it's unfreeRedistributable).
  unfreePredicate = pkg: with pkgs.lib; let
    allowPackageNames = [ "quake3-demodata" "quake3-pointrelease" ];
    allowLicenses = [ pkgs.lib.licenses.unfreeRedistributable ];
  in elem pkg.pname allowPackageNames &&
     elem (pkg.meta.license or null) allowLicenses;

in

rec {
  name = "quake3";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ <NAME> ];
  };

  # TODO: lcov doesn't work atm
  #makeCoverageReport = true;

  client =
    { pkgs, ... }:

    { imports = [ ./common/x11.nix ];
      hardware.opengl.driSupport = true;
      environment.systemPackages = [ pkgs.quake3demo ];
      nixpkgs.config.packageOverrides = overrides;
      nixpkgs.config.allowUnfreePredicate = unfreePredicate;
    };

  nodes =
    { server =
        { pkgs, ... }:

        { systemd.services.quake3-server =
            { wantedBy = [ "multi-user.target" ];
              script =
                "${pkgs.quake3demo}/bin/quake3-server +set g_gametype 0 " +
                "+map q3dm7 +addbot grunt +addbot daemia 2> /tmp/log";
            };
          nixpkgs.config.packageOverrides = overrides;
          nixpkgs.config.allowUnfreePredicate = unfreePredicate;
          networking.firewall.allowedUDPPorts = [ 27960 ];
        };

      client1 = client;
      client2 = client;
    };

  testScript =
    ''
      startAll;

      $server->waitForUnit("quake3-server");
      $client1->waitForX;
      $client2->waitForX;

      $client1->execute("quake3 +set r_fullscreen 0 +set name Foo +connect server &");
      $client2->execute("quake3 +set r_fullscreen 0 +set name Bar +connect server &");

      $server->waitUntilSucceeds("grep -q 'Foo.*entered the game' /tmp/log");
      $server->waitUntilSucceeds("grep -q 'Bar.*entered the game' /tmp/log");

      $server->sleep(10); # wait for a while to get a nice screenshot

      $client1->block();

      $server->sleep(20);

      $client1->screenshot("screen1");
      $client2->screenshot("screen2");

      $client1->unblock();

      $server->sleep(10);

      $client1->screenshot("screen3");
      $client2->screenshot("screen4");

      $client1->shutdown();
      $client2->shutdown();
      $server->stopJob("quake3-server");
    '';

})<commit_msg>nixos/quake3: convert test to python<commit_after>import ./make-test-python.nix ({ pkgs, ...} :

let

  # Build Quake with coverage instrumentation.
  overrides = pkgs:
    {
      quake3game = pkgs.quake3game.override (args: {
        stdenv = pkgs.stdenvAdapters.addCoverageInstrumentation args.stdenv;
      });
    };

  # Only allow the demo data to be used (only if it's unfreeRedistributable).
  unfreePredicate = pkg: with pkgs.lib; let
    allowPackageNames = [ "quake3-demodata" "quake3-pointrelease" ];
    allowLicenses = [ pkgs.lib.licenses.unfreeRedistributable ];
  in elem pkg.pname allowPackageNames &&
     elem (pkg.meta.license or null) allowLicenses;

in

rec {
  name = "quake3";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ domenkozar eelco ];
  };

  # TODO: lcov doesn't work atm
  #makeCoverageReport = true;

  client =
    { pkgs, ... }:

    { imports = [ ./common/x11.nix ];
      hardware.opengl.driSupport = true;
      environment.systemPackages = [ pkgs.quake3demo ];
      nixpkgs.config.packageOverrides = overrides;
      nixpkgs.config.allowUnfreePredicate = unfreePredicate;
    };

  nodes =
    { server =
        { pkgs, ... }:

        { systemd.services.quake3-server =
            { wantedBy = [ "multi-user.target" ];
              script =
                "${pkgs.quake3demo}/bin/quake3-server +set g_gametype 0 " +
                "+map q3dm7 +addbot grunt +addbot daemia 2> /tmp/log";
            };
          nixpkgs.config.packageOverrides = overrides;
          nixpkgs.config.allowUnfreePredicate = unfreePredicate;
          networking.firewall.allowedUDPPorts = [ 27960 ];
        };

      client1 = client;
      client2 = client;
    };

  testScript =
    ''
      start_all()

      server.wait_for_unit("quake3-server")
      client1.wait_for_x()
      client2.wait_for_x()

      client1.execute("quake3 +set r_fullscreen 0 +set name Foo +connect server &")
      client2.execute("quake3 +set r_fullscreen 0 +set name Bar +connect server &")

      server.wait_until_succeeds("grep -q 'Foo.*entered the game' /tmp/log")
      server.wait_until_succeeds("grep -q 'Bar.*entered the game' /tmp/log")

      server.sleep(10)  # wait for a while to get a nice screenshot

      client1.block()

      server.sleep(20)

      client1.screenshot("screen1")
      client2.screenshot("screen2")

      client1.unblock()

      server.sleep(10)

      client1.screenshot("screen3")
      client2.screenshot("screen4")

      client1.shutdown()
      client2.shutdown()
      server.stop_job("quake3-server")
    '';

})
{'fraction_non_alphanumeric': 0.1310557807373094, 'fraction_numerical': 0.01949430611850994, 'mean_word_length': 2.527569775357386, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '883733', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1733, 'n_words': 327}