1#!/usr/bin/env ruby 2# 3# Copyright 2016 gRPC authors. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Some tests are flaking by failing to dlopen grpc. Perform some sanity checks. 18this_dir = File.expand_path(File.dirname(__FILE__)) 19grpc_bin_dir = File.join(File.join(File.dirname(this_dir), 'lib'), 'grpc') 20grpc_c_sha256_path = File.join(grpc_bin_dir, 'grpc_c_sha256') 21grpc_c_so_path = if RUBY_PLATFORM =~ /darwin/ 22 File.join(grpc_bin_dir, 'grpc_c.bundle') 23 else 24 File.join(grpc_bin_dir, 'grpc_c.so') 25 end 26 27require 'digest' 28 29# first try to detect corruption b/t the build and now 30actual_sha256 = Digest::SHA256.file(grpc_c_so_path).hexdigest 31expected_sha256 = File.read(grpc_c_sha256_path).chomp 32raise "detected corruption in #{grpc_c_so_path}: sha256: |#{actual_sha256}| != expected sha256: |#{expected_sha256}|" if actual_sha256 != expected_sha256 33STDERR.puts "verified sha256 of #{grpc_c_so_path}" 34 35def try_command(command) 36 STDERR.puts "==== run |#{command}| BEGIN ====" 37 output = `#{command} || true` 38 STDERR.puts output 39 STDERR.puts "==== run |#{command}| DONE ====" 40end 41 42try_command('vm_stat') 43try_command('free') 44try_command('ulimit -v') 45 46# sanity check that we can load grpc in a child process, log things like available 47# memory on the off chance we might be low. 48pid = fork do 49 STDERR.puts "==== sanity check child process BEGIN ====" 50 def dump(file_path) 51 STDERR.puts "==== dump file: #{file_path} BEGIN ====" 52 if File.exist?(file_path) 53 File.open(file_path, 'r') do |file| 54 file.each_line do |line| 55 puts line 56 end 57 end 58 else 59 STDERR.puts "file: #{file_path} does not exist" 60 end 61 STDERR.puts "==== dump file: #{file_path} DONE ====" 62 end 63 dump("/proc/#{Process.pid}/limits") 64 dump("/proc/#{Process.pid}/status") 65 STDERR.puts "==== sanity check require grpc in child process BEGIN =====" 66 require 'grpc' 67 STDERR.puts "==== sanity check require grpc in child process DONE =====" 68 dump("/proc/#{Process.pid}/limits") 69 dump("/proc/#{Process.pid}/status") 70 STDERR.puts "==== sanity check child process DONE ====" 71end 72_, status = Process.wait2(pid) 73fail "sanity check require grpc in child process FAILED exit code #{status.exitstatus}" unless status.success? 74STDERR.puts "==== sanity check require grpc in child process SUCCESS =====" 75