<commit_before># VMTest

## Motivations

Some unit tests are dependent with Linux distributions.  To run them,
we can use `./run` to build them for Linux/AMD64 and run them in VMs
with corresponding Linux distributions installed.

`./run` runs built unit test binaries with command line parameter
`--invm`, which corresponds to the global variable `vmtest.InVM`.  So
we can write our Linux-distribution-dependent unit tests in the form
of:

```
func TestSomething(t *testing.T) {
    if *vmtest.InVM {
        ....
    }
}
```

## Prerequisite

`vmtest/run` requires
[Vagrant scp plugin](https://github.com/invernizzi/vagrant-scp).  To
install it, type

```
vagrant plugin install vagrant-scp
```

## Usage

An example is in `bootstrapper/dhcp`.  To run the tests in a Ubuntu VM
and then in a CentOS VM:

```
cd bootstrapper/dhcp
../vmtest/run
```

## Troubleshooting

### Out-Of-Memory

Some unit tests might need more memory than created by `vagrant init`;
or they will cause out-of-memory error.  For that case

### Anti-GFW

In order to use an HTTP proxy, we can change the following the line in
`vmtest/sh`

```
vagrant ssh -c "sudo /home/vagrant/$PKG.test -test.invm"
```

into

```
vagrant ssh -c "sudo http_proxy=xxxx https_proxy=yyyy /home/vagrant/$PKG.test -test.invm"
```<commit_msg>In response to comments from <NAME><commit_after># VMTest

## Motivations

Some unit tests are dependent with Linux distributions.  To run them,
we can use `./run` to build them for Linux/AMD64 and run them in VMs
with corresponding Linux distributions installed.

`./run` runs built unit test binaries with command line parameter
`--invm`, which corresponds to the global variable `vmtest.InVM`.  So
we can write our Linux-distribution-dependent unit tests in the form
of:

```
func TestSomething(t *testing.T) {
    if *vmtest.InVM {
        ....
    }
}
```

## Prerequisite

`vmtest/run` requires
[Vagrant scp plugin](https://github.com/invernizzi/vagrant-scp).  To
install it, type

```
vagrant plugin install vagrant-scp
```

## Usage

An example is in `bootstrapper/dhcp`.  To run the tests in a Ubuntu VM
and then in a CentOS VM:

```
cd bootstrapper/dhcp
../vmtest/run
```

## Troubleshooting

### Out-Of-Memory

Some unit tests might need more memory than that's created by `vagrant
init`.  However, `vagrant init` doesn't allow us to specify the amount
of memory.  In that case, please edit the `vm/Vagrantfile` file
generated by `vmtest/run` by yourself.

### Anti-GFW

In order to use an HTTP proxy, we can change the following the line in
`vmtest/sh`

```
vagrant ssh -c "sudo /home/vagrant/$PKG.test -test.invm"
```

into

```
vagrant ssh -c "sudo http_proxy=xxxx https_proxy=yyyy /home/vagrant/$PKG.test -test.invm"
```
{'fraction_non_alphanumeric': 0.11322828875045804, 'fraction_numerical': 0.0014657383657017222, 'mean_word_length': 3.7395833333333335, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '3282992', 'n_tokens_mistral': 953, 'n_tokens_neox': 900, 'n_words': 342}