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_unittests --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.
- chromium的C++ unit test是所谓的GTest。
- 然后我们就去http://cs.chromium.org搜这个文件的名字,看看它在哪个gn target,发现这个东西是net_unittest的一部分。也可以查找本地机器上源码,搜索*.gn,找到它的gn target目录。
- 或者可以:获取所有构建目标:
-
gn ls out/Default -
比如: //chrome/test:unit_tests -
构建这个目标,去掉//: ninja -C out/Default chrome/test:unit_tests - 最后运行test unit
- out/Debug/net_unittest --gtest_filter=*DiskCacheBackendTest.SparseEvict*
-
out\Default\unit_tests.exe --gtest_filter="PushClientTest.*"
(std中字符串字面常量,任意字符串都可以作为分割符:std:string s=fffxxxhahaha i'am here. she said:" no!"fffxxx
这里fffxxx是字符串的表示。
)
大概思路就是这样,至于具体能不能跑,可以参考一下chromium的这个文档。
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)
改了系统时间好了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2018-09-21 一张图看懂JVM
2018-09-21 异步化,高并发大杀器
2017-09-21 ubuntu 15 安装docker