chrome单元测试 单独编译 chromium的Gtest

 

D:\dev\electron7\src>ninja -C out/Testing net_unittests
out\Testing\net_unittests.exe --gtest_filter=*HttpContentDispositionTest.Filename*



运行:
out/Debug/net_unittest​s --gtest_filter=*DiskCacheBackendTest.SparseEvict*

 

测试源码:

另一个示例:

ninja -C out\Default blink_platform_unittests

out\Default\blink_platform_unittests.exe  --gtest_filter=*JPEGImageDecoderTest.downsampleImageSizeMultipleOf8*

源码:

// Tests that the JPEG decoder can downsample image whose width and height are
// multiples of 8, to ensure we compute the correct DecodedSize and pass correct
// parameters to libjpeg to output the image with the expected size.
TEST(JPEGImageDecoderTest, downsampleImageSizeMultipleOf8) {
  const char* jpeg_file = "/images/resources/gracehopper.jpg";  // 256x256

  // 1/8 downsample.
  Downsample(40 * 40 * 4, jpeg_file, gfx::Size(32, 32));

  // 2/8 downsample.
.....

输出

IMPORTANT DEBUGGING NOTE: batches of tests are run inside their
own process. For debugging a test inside a debugger, use the
--gtest_filter=<your_test_name> flag along with
--single-process-tests.
Using sharding settings from environment. This is shard 0/1
Using 1 parallel jobs.
Note: Google Test filter = JPEGImageDecoderTest.downsampleImageSizeMultipleOf8
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from JPEGImageDecoderTest
[ RUN      ] JPEGImageDecoderTest.downsampleImageSizeMultipleOf8
[12408:11000:ERROR:image_decoder.cc(445)] 1
[12408:11000:ERROR:image_decoder.cc(447)] 2
[12408:11000:ERROR:image_decoder.cc(448)] 0.007389 s
[12408:11000:ERROR:image_decoder.cc(445)] 1
[12408:11000:ERROR:image_decoder.cc(447)] 2
[12408:11000:ERROR:image_decoder.cc(448)] 0.001333 s
[12408:11000:ERROR:image_decoder.cc(445)] 1
[12408:11000:ERROR:image_decoder.cc(447)] 2
[12408:11000:ERROR:image_decoder.cc(448)] 0.001572 s
[12408:11000:ERROR:image_decoder.cc(445)] 1
[12408:11000:ERROR:image_decoder.cc(447)] 2
[12408:11000:ERROR:image_decoder.cc(448)] 0.001469 s
[12408:11000:ERROR:image_decoder.cc(445)] 1
[12408:11000:ERROR:image_decoder.cc(447)] 2
[12408:11000:ERROR:image_decoder.cc(448)] 0.00205 s
[12408:11000:ERROR:image_decoder.cc(445)] 1
[12408:11000:ERROR:image_decoder.cc(447)] 2
[12408:11000:ERROR:image_decoder.cc(448)] 0.005453 s
[12408:11000:ERROR:image_decoder.cc(445)] 1
[12408:11000:ERROR:image_decoder.cc(447)] 2
[12408:11000:ERROR:image_decoder.cc(448)] 0.00262 s
[       OK ] JPEGImageDecoderTest.downsampleImageSizeMultipleOf8 (41 ms)
[----------] 1 test from JPEGImageDecoderTest (43 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (48 ms total)
[  PASSED  ] 1 test.
[1/1] JPEGImageDecoderTest.downsampleImageSizeMultipleOf8 (41 ms)
SUCCESS: all tests passed.
Tests took 0 seconds.

  1. chromium的C++ unit test是所谓的GTest
  2. 然后我们就去搜这个文件的名字,看看它在哪个gn target,发现这个东西是net_unittest的一部分。也可以查找本地机器上源码,搜索*.gn,找到它的gn target目录。
  3. 或者可以:获取所有构建目标:
  4. gn ls out/Default
  5. 比如:
    //chrome/test:unit_tests
  6. 构建这个目标,去掉//:
    ninja -C out/Default chrome/test:unit_tests
  7. 最后运行test unit
    1. out/Debug/net_unittest​ --gtest_filter=*DiskCacheBackendTest.SparseEvict*
    2. out\Default\unit_tests.exe --gtest_filter="PushClientTest.*" 

(std中字符串字面常量,任意字符串都可以作为分割符:std:string s=fffxxxhahaha i'am here. she said:" no!"fffxxx

这里fffxxx是字符串的表示。

)

大概思路就是这样,至于具体能不能跑,可以参考一下chromium的这个文档。

您可以在GitHub页面上找到有关GoogleTest的更多信息。
 
 
gn args out\Default 

gn gen out\Default --ide=vs2017 --fillter="//base:*;//chrome:*;//components:*;//net:*;//net:*;" --sln=chrome --no-deps

ninja -C out\Default chrome

#单元测试编译
ninja -C out\Default chrome\test:unit_tests

报错:

D:\dev\electron7\src>out\Testing\net_unittests.exe --gtest_filter=*HttpContentDispositionTest.Filename*
ERROR: This build is more than 70 days out of date.
This could indicate a problem with the device's clock, or the build is simply too old.
See crbug.com/666821 for why this is a problem
    base::Time::Now() --> 2020-09-21 03:04:09.533 UTC (13245131049533601)
    base::GetBuildTime() --> 2020-06-07 05:00:00.000 UTC (13235979600000000)

改了系统时间好了

posted @ 2020-09-21 10:40  Bigben  阅读(1528)  评论(1编辑  收藏  举报