The invention relates to a method and a device for generating a test program for verifying the function of a microprocessor. The method comprises the following steps of: A, randomly generating mu+lamda individuals, saving the individuals as an original generation population, and taking the original generation population as the current population; B, converting the individuals in the current population into the test program by combining an instruction library; C, performing simulation execution on the test program obtained by converting each individual in the current population to generate a functional coverage report; D, directly performing the step E if the current population is the original generation population, and performing intersection and variation operation on the individuals in the current population for lamda times, saving the generated new individuals in the current population, and performing the step E if the current population is not the original generation population; E, selecting at least mu individuals from the current population as a new-generation population according to the functional coverage report; and F, outputting test program sets corresponding to the individuals in the new-generation population if the stop condition is met, and taking the new-generation population as the current population and returning to the step B if the stop condition is not met.