github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/test/benchmarks/tools/fio_test.go (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package tools
    16  
    17  import "testing"
    18  
    19  // TestFio checks the Fio parsers on sample output.
    20  func TestFio(t *testing.T) {
    21  	sampleData := `
    22  {
    23    "fio version" : "fio-3.1",
    24    "timestamp" : 1554837456,
    25    "timestamp_ms" : 1554837456621,
    26    "time" : "Tue Apr  9 19:17:36 2019",
    27    "jobs" : [
    28      {
    29        "jobname" : "test",
    30        "groupid" : 0,
    31        "error" : 0,
    32        "eta" : 2147483647,
    33        "elapsed" : 1,
    34        "job options" : {
    35          "name" : "test",
    36          "ioengine" : "sync",
    37          "size" : "1073741824",
    38          "filename" : "/disk/file.dat",
    39          "iodepth" : "4",
    40          "bs" : "4096",
    41          "rw" : "write"
    42        },
    43        "read" : {
    44          "io_bytes" : 0,
    45          "io_kbytes" : 0,
    46          "bw" : 123456,
    47          "iops" : 1234.5678,
    48          "runtime" : 0,
    49          "total_ios" : 0,
    50          "short_ios" : 0,
    51          "bw_min" : 0,
    52          "bw_max" : 0,
    53          "bw_agg" : 0.000000,
    54          "bw_mean" : 0.000000,
    55          "bw_dev" : 0.000000,
    56          "bw_samples" : 0,
    57          "iops_min" : 0,
    58          "iops_max" : 0,
    59          "iops_mean" : 0.000000,
    60          "iops_stddev" : 0.000000,
    61          "iops_samples" : 0
    62        },
    63        "write" : {
    64          "io_bytes" : 1073741824,
    65          "io_kbytes" : 1048576,
    66          "bw" : 1753471,
    67          "iops" : 438367.892977,
    68          "runtime" : 598,
    69          "total_ios" : 262144,
    70          "bw_min" : 1731120,
    71          "bw_max" : 1731120,
    72          "bw_agg" : 98.725328,
    73          "bw_mean" : 1731120.000000,
    74          "bw_dev" : 0.000000,
    75          "bw_samples" : 1,
    76          "iops_min" : 432780,
    77          "iops_max" : 432780,
    78          "iops_mean" : 432780.000000,
    79          "iops_stddev" : 0.000000,
    80          "iops_samples" : 1
    81        }
    82      }
    83    ]
    84  }
    85  `
    86  	fio := Fio{}
    87  	// WriteBandwidth.
    88  	got, err := fio.parseBandwidth(sampleData, false)
    89  	var want float64 = 1753471.0 * 1024
    90  	if err != nil {
    91  		t.Fatalf("parse failed with err: %v", err)
    92  	} else if got != want {
    93  		t.Fatalf("got: %f, want: %f", got, want)
    94  	}
    95  
    96  	// ReadBandwidth.
    97  	got, err = fio.parseBandwidth(sampleData, true)
    98  	want = 123456 * 1024
    99  	if err != nil {
   100  		t.Fatalf("parse failed with err: %v", err)
   101  	} else if got != want {
   102  		t.Fatalf("got: %f, want: %f", got, want)
   103  	}
   104  
   105  	// WriteIOps.
   106  	got, err = fio.parseIOps(sampleData, false)
   107  	want = 438367.892977
   108  	if err != nil {
   109  		t.Fatalf("parse failed with err: %v", err)
   110  	} else if got != want {
   111  		t.Fatalf("got: %f, want: %f", got, want)
   112  	}
   113  
   114  	// ReadIOps.
   115  	got, err = fio.parseIOps(sampleData, true)
   116  	want = 1234.5678
   117  	if err != nil {
   118  		t.Fatalf("parse failed with err: %v", err)
   119  	} else if got != want {
   120  		t.Fatalf("got: %f, want: %f", got, want)
   121  	}
   122  }