M spec pretty much nailed it. they know what the engine is gonna be used for, what components it will be made of, the tolerances for said components,  approximately what power it will make etc.
and becaue they have been making engines for years already, their calcualtions and projections tend to be very close to actual results.
then, to quote someone, testing, testing, testing. a batch of engines will be tested, sometimes with variations in the components (cams, valves, pistons etc) some will be tested in cold conditions, others will be pretty much overheating all the time, some will be under load, others not so much, they use different fuel quality, timing, oils even, until they get a compromise between the performance they want and the cost.
then there is even more testing with the engine in the vehicle; hot weather, cold weather, high speed durability testing, first gear only, second gear only, third gear only etc, fans disengaged, fans permanently on, low electrical output from alternator, low coolant, low oil etc etc etc.
they try to account for every single thing that the engine could encounter in its life after they sell the car. mostly, they test to make sure that the engine will hold up for at least the duration of the warranty period. 
some manufaturers, toyota and honda come to mind, test individual parts and engines till failure, and if a small, preferably cheap, modification will yeild a longer lasting part/ engine, they will employ it. and they have reaped the harvest of percieved quality/ good engineering as a result.
yeah it goes beyond just figuring out what the redline should be.
unless youre mclaren and you employ things like pure gold heat conductors/ deflectors.